.Net: Native Methods (Beta)

Common variables and dictionaries

Before delving into the native methods themselves, it's important to be aware of a crucial detail when creating low-code triggers: the use of currentData, beforeSave and afterSave.

These three dictionaries contain valuable information about the data sent by the user and about the database itself.

  • currentData: this is the dictionary that contains the information the user has sent by acting. For example, if a user drags a card in a kanban to the "In Progress" stage, then currentData['stage'] will contain "In Progress".
  • beforeSave: this is the dictionary that contains the information about the record before it is changed (that is, before currentData is saved to the database). For example, if a user drags a card in a kanban from "New" to the "In Progress" stage, then currentData['stage'] will contain "In Progress", and beforeSave["stage"] will contain "New". Bonus: if you change the beforeData in a synchronous, before create/update trigger, this new information will be saved to the record.
  • afterSave: this is the dictionary that contains the information about the record after it is changed (that is, after currentData is saved to the database). For example, if a user drags a card in a kanban from "New" to the "In Progress" stage, then currentData['stage'] will contain "In Progress", as will afterSave["stage"]. Bonus: some information will only be available in afterSave. For example, in an After a record is created trigger, the record's id will only be contained in afterSave, as the id is only registered after the record is saved to the database.
  • currentUser: this is the dictionary that contains the information about a user who has triggered the automation. Particularly useful for identification, as it contains id_user, email, and name.

Two other dictionaries are only present when using low-code Functions instead of Triggers:

  • recordData: this holds the information of the record when the Function is invoked through a Button + Run a function combination. In this scenario, it should also be noted that N:1 connection fields will bring the first level of nested information. For example, if you have a "client" field that points to a record in the "Clients" table, you can access information such as recordData['client']['name'] without needing to run a separate search.
  • params: this holds the information you receive when activating the Function through a webhook. For example, if you send the JSON payload {"status":"New"} to the webhook, you can access that information through params['status'] in the Function.
var obj = new {
  field_1 = recordData["name"].ToString(),
  field_2 = (int)recordData["number"]
};

Auxiliar Functions

This topic show function will helps to development in low code. All functions are static you don't need instance the class.

  • Functions.serialize: this function will serialize any object and return string data.

    • Example:
    var myObj = new {name = "John Doe", age = 40};
    string jsonData = Functions.serialize(myObj);
    
  • Functions.deserialize: this function will deserialize json string and return dynamic data.

    • Example:
    string json = "{\"name\":\"John Doe\", \"age\": 40}";
    dynamic obj = Functions.deserialize(json);
    obj.name;
    
  • Functions.deserialize: this function will deserialize json string and return dynamic data.

    • Example:
    string json = "{\"name\":\"John Doe\", \"age\": 40}";
    dynamic obj = Functions.deserialize(json);
    obj.name;
    
  • Functions.response: this function will data argument in json type to webhook. It's required use return with this function.

    • Example:
    var myObj = new {name = "John Doe", age = 40};
    return Functions.response(myObj);
    
  • Functions.stopCodeExecution: this function will stop the low code execution and will rollback the data. It's required use return with this function.

    • Example:
    int variable = 0;
    if (variable == 0){
    	return Functions.stopCodeExecuton("variable can't be zero");
    }	
    

Native Methods

This is a list of native methods and how to use them in low-code triggers.

Create Record

To create a record use the table method using the table name as a parameter, then the insert method using object as parameter. Example:

var obj = new {
  name = "John Doe",
  email = "[email protected]"
};

var results = jestor.Tables("table_name").Insert(obj);
return Functions.response(results.data);

Edit Record

To edit a record use the table method using the table name as a parameter, then the update method using the id of the record that will be changed and dictionary of data as a parameter. Example:

int _id = 1;
var dtc = new Dictionary<string, dynamic>();
dtc.Add("field_1", "value");

var results = jestor.Tables("table_name").Update(_id, dtc);
return Functions.response(results.data);

Delete Record

To delete a record use the table method using the table name as a parameter, then the delete method using the record id as a parameter. Example:

var recordId = 1;
jestor.Tables('table_name').Delete(recordId);

List Records

To list records use the table method using the table name as a parameter, then the get method. Example:

var filters = new List<Filter>();
filters.Add(new Filter("name", "John Doe", "string", Operators.Equal));

var dados = jestor.Tables("table_name").Get(filters);

return Functions.response(dados.data);

The Filter object receives the following parameters:

  • field: str (field name).
  • value: str (field value).
  • type: str (field type).
  • operator: str (operators can be found in the Operators class).
    • Operators:
      • Equal
      • ITS_DIFFERENT_FROM
      • CONTAINS
      • DOES_NOT_CONTAIN
      • startsWith
      • LIST_IN
      • LIST_NOT_IN
      • NULL
      • nullOrEmpty
      • is_not_null
      • nullOrFilled
      • NUMBER_GREATER_THAN
      • NUMBER_GREATER_THAN_OR_EQUAL_TO
      • NUMBER_LESS_THAN
      • NUMBER_LESS_THAN_OR_EQUAL_TO

Create User

To create a user use the user() method, then the createUser() method passing a list as a parameter. This list must contain the fields in order [email, password, profile_id, name]. Example:

bool sendEmailToValidation = true;
int profileId = 9999;
var _user = jestor.User().CreateUser("email", "passord", profileId, "name", sendEmailToValidation, Jestor_SDK_Net.Types.Seats.member);

Inactive User

To inactive a user use the user() method, then the InactiveUser()_ method passing the user id. Example:

int userId = 999;
var _user = jestor.User().InactiveUser(userId);

List Users

To list users use the user() method, then the get method. The get method accepts the following parameters:

  • filters: List[Filter] = null,
  • limit: int = 100,
  • page: int = 1,
  • sort: str = None

Example:

var filters = new List<Filter>();
filters.Add(new Filter("email", "[email protected]", "string", Operators.CONTAINS));

var dados = jestor.User().Get(filters);

Execution Functions

Some methods you can call using the method ExecutionFunction passing parameters as function name and array of parameters.

Below have the examples how to use.

Download File

This method you can download a file from url and save in Jestor file fields. The return will be base64 image.

string url = "https://example.com/example_image.png";
var base64image = jestor.ExecuteFunction("downloadFile", new object[] { url });

Generate PDF

This method allows you to create a custom PDF from a string containing custom HTML, saving it locally to Jestor. The example below is a trigger creates a PDF file and updates a record, adding the file to a files field.


string html = @"
<body>
    <div class='container'>
        <div class='card' id='makepdf'> 
            <h2>Welcome to Jestor</h2>
            <ul>
                <li><h4>We are going to generate a pdf from the area inside the box</h4></li>
                <li><h4>This is an example of generating pdf from HTML during runtime</h4></li>
            </ul>
        </div>
        </div>
</body>
";

var pdf = jestor.ExecuteFunction("generatePDF", new object[] { html, "A4", "portrait" });

Create New File

This function uses two arguments to create a file from some sort of content:

A variable containing the content.
The extension of the file to be created.
The example below will create a .txt file that contains the text "test file content" and put it on an attachment field.


string newFile = jestor.ExecuteFunction("createNewFile", new object[]{"test file content","txt"});

Create New File Base64

This function uses two arguments to create a file from some sort of content:

A variable containing the content base in 64 format.
The extension of the file to be created.
The example below will create a .txt file that contains the text "test file content" and put it on an attachment field.


string newFile = jestor.ExecuteFunction("createNewFileFromBase64", new object[]{"dGVzdCBmaWxlIGNvbnRlbnQ","txt"});

Get Content File

This function gets the content from a file inside Jestor itself. The example below will download the .jpg file from the picture field we passed as an argument and return in base64 format.


string base64Content = jestor.ExecuteFunction("getContentFile", new object[]{currentData["pictures"]});