Question

Freedom UI - ESQ count

Hello,

 

Please provide me with a documentation and script that help us to count the number of records based in some conditions

 

Thank you,

Georges

Like 0

Like

5 comments

For client side Freedom UI EntitySchemaQuery is no longer used. Instead use the Model class for client side queries. See more here: https://customerfx.com/article/querying-data-using-filter-conditions-via-the-model-class-equivalent-to-enityschemaquery-in-a-creatio-freedom-ui-page/

Ryan

Ryan Farley,

Thank you Ryan,

I am trying to use the ESQ for example:
 

const accountModel = await sdk.Model.create("Account");

                                    const filters = new sdk.FilterGroup();
                                    await filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrREQID", customerComplaintID);
                                    const newFilters = Object.assign({}, filters);
                                    newFilters.items = filters.items;
                                    const partners = await accountModel.load({
                                        attributes: ["Id", "Name"],
                                        parameters: [{
                                            type: sdk.ModelParameterType.Filter,
                                            value: newFilters
                                        }]
                                    });
                                    

const numberOfRecords = partners.length;
                                    const partner = partners[0];

in order to get the number of records, but the error is:

under validators section
 

validators: /**SCHEMA_VALIDATORS*/{} /**SCHEMA_VALIDATORS*/

it shows an error on sdk as below image

 

 

 

Thank you,

Georges

Based on the error you're getting, you are missing the "@creatio-devkit/common" from the SCHEMA_DEPS. Refer to the particle again. 

However, based on the location, it's likely that something else is misaligned in the code, missing comma, curly brace, etc.


I put the below code:

validators: /**SCHEMA_VALIDATORS*/{
          "usr.ValidateFieldValue": {
              "validator": function (config) {
                  return function (control) {
                      const accountModel = await sdk.Model.create("Account");
                const filters = new sdk.FilterGroup();
                  await filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "UsrActive", request.value);
                await filters.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Id", "05eacefd-2e8c-4187-a705-7d2c060b7794");
                            const newFilters = Object.assign({}, filters);
                            newFilters.items = filters.items;
                            const accounts = await accountModel.load({
                                attributes: ["Id", "Name"],
                                parameters: [{
                                    type: sdk.ModelParameterType.Filter,
                                    value: newFilters
                                }]
                            });
                const numberOfRecords = accounts .length;
                alert(numberOfRecords); 
                    if (numberOfRecords <= 3) {
                        return null;
                    } else {
                        return {
                            "usr.ValidateFieldValue": { message: config.message }
                        };
                    }
                    
                  };
              },
              "params": [
                  {
                      "name": "invalidName"
                  },
                  {
                      "name": "message"
                  }
              ],
              "async": false
          }
      }/**SCHEMA_VALIDATORS*/


and i defined this : "@creatio-devkit/common"

but the error is same as the attached image

 

Hello again,

 

I tried to put async before the function as below:

validators: /**SCHEMA_VALIDATORS*/{
          "usr.ValidateFieldValue": {
              "validator": function (config) {
                  return async function (control) {
                      var test = await request.$context.PDS_USR_rghj54;
          }
      }/**SCHEMA_VALIDATORS*/

I noticed that the role of validators has been changed,
However, I tried also to write as below code:

Remove async and await


validators: /**SCHEMA_VALIDATORS*/{
          "usr.ValidateFieldValue": {
              "validator": function (config) {
                  return  function (control) {
                      var test =  request.$context.PDS_USR_rghj54;
          }
      }/**SCHEMA_VALIDATORS*/

the test field returns an undefined value

how can I get the field value on the validator section

Thank you,

Georges

 

Show all comments