I am working on a scenario where I need to get Records (With Id and Name) from another object.
In Model class, we can get one record but how to get a Collection of records with a filter/Parameter "Name" it should get all the records with the same Name.
There is an issue in current versions of Creatio with the filter classes, such as FilterGroup etc, being applied to model load/queries. I've been reporting this issue since 8.0.6 (#SR-01182879) but it's still not yet fixed in 8.0.9, very frustrating (I've been told it will be fixed in 8.1 #SR-01198668 🤞🏻). However you can still use them with a small workaround. The example below will get all Accounts that have Type = Customer:
// make sure to add "@creatio-devkit/common" as sdkconst accountModel = await sdk.Model.create("Account");const customerFilter =new sdk.FilterGroup();
await customerFilter.addSchemaColumnFilterWithParameter(sdk.ComparisonType.Equal, "Type.Name", "Customer");// This is the workaround you have to do for the filters to work.// Shallow copy to a new object and then reassign the items collection.const newCustomerFilter = Object.assign({}, customerFilter);
newCustomerFilter.items= customerFilter.items;// now use new shallow copied filters in the queryconst customers = await accountModel.load({
attributes:["Id", "Name", "Type"],
parameters:[{
type: sdk.ModelParameterType.Filter,
value: newCustomerFilter
}]});// the customers variable is now an array of accounts with Id, Name, and Type columns
console.log(customers);
The whole issue with the FilterGroup is that the items collection doesn't get unrolled from a collection to an array - the copy forces the object to flatten out how it's expected by the underlying DataService call.
Verify that the column name is correct. In the accountModel.load your passing the attributes array with "DateTimeAttribute_x2whel6", this needs to be the column name in the object/table (which will likely start with a Usr)