Is it possible to set a default value for fields in a given page in Freedom UI?

We're trying to set it up so that one of our mini pages used for record creation (wherever the record creation is started from, as there are several screens with a button to create the record) always has a default value set. We can't set the default on the entity, as records coming in from the integrations shouldn't have these fields set to any default, only set to whatever comes in through the interface. Is there any configuration that can be done to set default values for pages themselves?

 

We know about setting defaults when calling the crt.CreateRecordRequest request which is done from the calling page, but would ideally like to be able to set it one time for the creation mini page itself to avoid code duplication. We are on 8.1.0

Like 1

Like

5 comments

You can setup a business rule if the attribute is not filled in then you set a static value. This will work only on the interface.

Thanks for the suggestion Franck, and interesting/concerning that the entity-level business rules only apply when creating records through the UI and not for all data!

 

Unfortunately the business rule value setting is much too limited in Creatio for what we need, only being able to set to a constant/static value which is defined when setting up the business rule. We need to be setting the value based on some logic through code, but would ideally be doing so with declarative code rather than imperative code which modifies the fields manually.

Hello Harvey,

The most general way to set the default values for a mini-page is to transfer them in ModelInitConfigs via crt.OpenPageRequest:

modelInitConfigs: [{defaultValues: [{AttributeName: 'AttributeValue'}]}]

But if you want to avoid transferring the values in every place you open the mini-page, consider the following implementation in the mini-page view model:

  1. Set the attribute value in the "crt.HandleViewModelInitRequest":
    request.$context.AttributeName = “AttributeValue”;
  2. Provide it not to be overridden to default null value in "crt.HandleViewModelAttributeChangeRequest":
    if (request.attributeName === "AttributeName" && request.value === null) {
          request.$context.AttributeName = “AttributeValue”;
    }

     

Best regards, Natalia

Hi Natalia,

 

Thanks for the reply, those will definitely be useful - for example I didn't know you could set default values when calling the crt.OpenPageRequest, I thought it was only possible to do so using the crt.CreateRecordRequest, so thanks for that!

 

I believe the workaround for putting the logic in the mini-page would mostly work, but with the following caveats:

1. You would not be able to clear the value of the field manually, which is unfortunate

2. This would make a change to the page that would cause the confirmation dialog to appear if closing the mini-page without the user making any modifications to data - not the end of the world, but it would be nice to avoid that

 

A quick question - what is the difference between simply assigning a request.$context.AttributeName using 

request.$context.AttributeName = "value"

Vs using the _setAttributeValue method in your reply? Is there any functional difference between the two, or is it just preference?

 

Many thanks,

Harvey

Harvey Adcock,

 

Hi, 

Sure, setting the mini page default values via HandleViewModel InitRequest and HandleViewModelAttributeChangeRequest has some disadvantages. That’s why we recommend using ModelInitConfigs in OpenPageRequest.

 

However, it may still be used if the user doesn’t need to set the field value to null. Especially considering the facts that:

- removing the string field means setting a value to an empty string (not null);

- the numeric field value might be set to 0 instead of removing it.

 

The question of silent saving has already been discussed in the separate feed - https://community.creatio.com/questions/it-possible-make-changes-attributes-code-freedom-ui-silently .

 

Regarding your question about setting the attribute value – I clarified it with our R&D department. There is no functional difference between the two approaches, but only the direct assigning is recommended to use as the most stable method:

request.$context.AttributeName = "value"

Thank you for such an important question. I have already changed my examples accordingly.

 

Best regards,

Natalia

Show all comments