Is it possible to make changes to attributes from code in Freedom UI "silently"?
I'm overriding the HandleViewModelAttributeChangeRequest request handler in client code, and want to set a hidden parameter used for showing/hiding fields and making them required/not required in this code when the page first loads, but I don't want this change to be detected by Creatio as a save-able change so that it thinks there is a change to be saved when closing the page. Is it possible to do this? I've tried setting the "silent" property of the request to true in the HandleViewModelAttributeChangeRequest handler and also tried setting the "IsChanged" property of the request.$context to false after changing the attribute value, but neither of these seems to prevent the "You have unsaved changes that will be lost. Continue?" dialog from showing when closing the page.
I'm currently using Creatio 8.1.0
Like
Can you please provide some direct example of what you are trying to achieve since unfortunately it's not obvious to us what is performed on the page at the moment, what is the expected result and what is the actual result? Maybe some steps to reproduce it in the local application (like the following:
1) Add column A
2) Add attribute B
3) Connect B to A in the following manner
4) Go to the page where the column and the attribute were added
5) Do "this"
6) Expected result is C
7) Actual result is D
) .
Thank you!
Oleg Drobina,
Basically all I want is to be able to set the value of an attribute in code without triggering the "You have unsaved changes that will be lost. Continue?" message when you leave the page. Is this possible?
Harvey Adcock,
I tried to reproduce the issue, but changing the value of the virtual attributes (like attributes created to control the visibility of the field) by itself does not cause this dialog to appear.
Please ensure that no other changes need to be saved on the page. Or provide us with additional information describing the exact steps to reproduce the issue.
Best regards,
Natalia
Natalia Kalynovska,
Sorry, I was probably not detailed enough in my abbreviated version - the changes are actually to an attribute that is based over a real column on the entity, so not a virtual attribute. Is there any way to modify such a field in code without triggering the dialog?
Hello Harvey,
To change the field without triggering the dialog, you should save it at once.
It could be implemented by adding the following code to the HandleViewModelAttributeChangeRequest:
…
if (request.attributeName === “[Name of the attribute]”) {
const saveResult = await this.handlerChain.handlerChain$.process({
type: "crt.SaveRecordRequest",
preventCardClose: true,
$context: request.$context
});
}
…
Please pay attention that too many saving requests may decrease performance.
Another way is to save the necessary changed values to a virtual attribute first, and then extract all of them (set attributes values) and initiate SaveRecordRequest while closing the page (in crt. ClosePageRequest). This approach has some disadvantages:
- you need to manually adjust the visibility of “SaveButton” and “CloseButton“ by adding the corresponding merge operations to “viewConfigDiff” of ListPage and FormPage modules (see example - https://community.creatio.com/questions/how-remove-closesave-button-custom-section);
- data would be saved only on a close/back button click.
And again – you should provide some conditions in order not to store too many changes.
Additionally, starting from the 8.1.1 Creatio version, the dialog may be prevented by adding to handlers the overridden “crt.CanDiscardUnsavedDataRequest” handler:
{request: "crt.CanDiscardUnsavedDataRequest", handler: async (request, next) => {return true;}},
However, it still requires manually adjusting the button's visibility and providing proper data saving.
Best regards,
Natalia
Thanks Natalia, it would be really useful to have the functionality for making silent changes from code that existed in Classic UI added back into Freedom UI - see this post for what was possible in Classic: https://community.creatio.com/questions/change-value-field-without-firing-changed-events
The utility can be in setting fields from code when a create record page loads based on more complicated conditions than you can define in business rules/by other means, but not causing the user additional clicks to cancel or think that they might lose work.