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)
For example, account types: we have 2 inactive values in our Account Type lookup: Our company & Contractor
In classic UI, when you work on list & form pages, these 2 values will not show up, but in Freedom UI yes (see screenshots below). Same scenario for inactive contacts, inactive accounts, inactive fields in other lookups, etc....
Indeed sorry, we call it "inactive" but it's deactivated records.
You activate the feature for any object by creating a replacing object, here for accounttype, and you click the OOTB feature "Allow records deactivation"
Thank you Bogdan. That could work in case of a multi instance list, like the list of Contacts. What If I have only one contact related to a custom entity, like the example described?
Does anyone possibly have a code example on the new Freedom page showing how to calculate the difference of values of two page fields and write it into a third field? For example: payment balance = Amount-PaymentAmount Maybe there's also a code example on how to get the exchange rate on the date specified in the Date field according to the Currency field or an example of how to refer to another object to get a value from it.
I have tried to Create a custom Detail in my Custom Section but not able to bind it with "Id" of the Parent Object as in Classic ui When we Create Detail it Automatically fetch the Current Record if and we are able to see the list in detail for current record. Can anyone help how to do the same in Freedom UI
In the new interface, the details are configured similarly to the mechanism used in the old interface. It also includes automatic mapping to the ID of the current record, so there is no need to add it separately. For example, in the "Orders" detail added to the "Account" section by default, we can see that the detail displays records where Account.Id (of the current record) is equal to Order.AccountId.
As for now, you could do the following - in this example I have a lookup for ContactType and will retrieve the Description once selected. You'll ned to know the actual attribute name for the lookup which you can see in the viewDiffConfig for the control as:
control: "$SomeAttributeName" (this is the attribute name, minus the "$")
Then, add a change request handler like this:
{
request:"crt.HandleViewModelAttributeChangeRequest",
handler: async (request, next)=>{// listen for changes to the Lookup field attributeif(request.attributeName==="LookupAttribute_spr6dlv"&&!request.silent){// get the selected value
var lookupVal = await request.$context.LookupAttribute_spr6dlv;// retrieve the descriptionconst model = await sdk.Model.create("ContactType");const results = await model.load({
attributes:["Description"],
parameters:[{
type: sdk.ModelParameterType.PrimaryColumnValue,
value: lookupVal.value}]});const desc = results[0].Description;// set the other column's attribute with the description
request.$context.SomeOtherAttribute= desc;}return next?.handle(request);}}
value: "38ea507c-55e6-df11-971b-001d60e938c6" - Id here can be dynamically set as some variable that is received from the context. To set the result for the column (in this case for the UsrSubjectDetails):
As for now, you could do the following - in this example I have a lookup for ContactType and will retrieve the Description once selected. You'll ned to know the actual attribute name for the lookup which you can see in the viewDiffConfig for the control as:
control: "$SomeAttributeName" (this is the attribute name, minus the "$")
Then, add a change request handler like this:
{
request:"crt.HandleViewModelAttributeChangeRequest",
handler: async (request, next)=>{// listen for changes to the Lookup field attributeif(request.attributeName==="LookupAttribute_spr6dlv"&&!request.silent){// get the selected value
var lookupVal = await request.$context.LookupAttribute_spr6dlv;// retrieve the descriptionconst model = await sdk.Model.create("ContactType");const results = await model.load({
attributes:["Description"],
parameters:[{
type: sdk.ModelParameterType.PrimaryColumnValue,
value: lookupVal.value}]});const desc = results[0].Description;// set the other column's attribute with the description
request.$context.SomeOtherAttribute= desc;}return next?.handle(request);}}
I have a requirement where "A" is a date field and "B" is a boolean. When a record is created, it should calculate the number of days left until "A" arrives. If the number of days left is less than 45, then the value of "B" should be changed to "true".
Note : I m using Freedom UI. Also if this is possible through Bussiness Process please Advise.
If you are referring to the way the data is represented, it depends on the type of the column (in order to make the value not have zero after it - make the column integer)
If you want to show a checkbox that would be ticked if a certain number is reached and you do not want to use code, keep the column in which you store the number of days, and on the base of it, build a business rule that "if the number of days is reached, then make the box true"