I need to make a request to a custom handler whenever a specific integer field changes its value in a Freedom UI page. The field can be 0, 1, or 2, and it’s modified by a business rule (not by the user), so it’s read-only.
I’ve been trying to achieve this using crt.HandleViewModelAttributeChangeRequest, but it doesn’t seem like the most effective way. My goal is to execute custom logic in my handler whenever this field’s value changes.
Use case details:
The field is read-only and changes internally (via business logic).
I need to detect when its value changes (0 → 1, 1 → 2, etc.) and trigger my handler.
Has anyone faced a similar scenario? What’s the recommended way to handle this in Creatio? Any examples or suggestions would be greatly appreciated!
What issues are you having with crt.HandleViewModelAttributeChangeRequest that make you want to use an alternative? This is the handler I would use.
If you want to encapsulate your logic into a custom handler, you can do so and then call that custom handler from the crt.HandleViewModelAttributeChangeRequest handler, which can allow more readable code, if that's the issue you're facing.
If the issue is that the handler is triggered when opening an existing record but you don't want it to be, you can use the request.silent property to only run your handler when the change is not silent (i.e. that it was caused by an actual state change rather than just the page loading).
I think the reason for why you aren't having success with the attribute change handler is key for understanding the requirement.
To explain my use case in more detail, my main issue is the following: I have an identification number field, and when this field changes, a custom handler should be triggered (currently I’m using crt.HandleViewModelAttributeChangeRequest). In this handler, I run a process that calls a web service to check whether the number is valid. If it’s not valid, a validation message should be triggered.
The problem I’m facing with crt.HandleViewModelAttributeChangeRequest is that the validation is triggered every time the user enters a single digit. So, if the ID is 10 digits long, the validation runs 10 times — once for each keystroke — because at each moment the number is still incomplete and therefore considered invalid.
Additionally, when a the validation field (the one mentioned before) changes, the same handler should be triggered.
So my current idea is to use a blur event on the identification number field to trigger a custom handler only when the field loses focus — avoiding premature validation on every keystroke. Then, for the read-only validation field, I want to call the same custom handler programmatically when that field’s value changes. I can’t use the blur event in because, this validation field is read-only.
My question now is: how can I detect changes in a read-only field and trigger a custom handler in that case?
If going via the blur event route, could you write a custom request handler like I suggested, trigger that request handler on the blur event (see here for triggering a request handler on field blur here: https://community.creatio.com/questions/which-are-events-field-can-be-handled-freedomui , not sure how to do any generic HTML DOM event unfortunately) and then also trigger that request handler from crt.HandleViewModelAttributeChangeRequest for just when the read only field changes?
Regarding the first option, it wouldn’t be possible because the field needs to be validated before saving—if it’s invalid, the save operation should be blocked.
As for the second option, that might actually work. If there’s no other way to trigger a custom handler when the field changes—other than using crt.HandleViewModelAttributeChangeRequest—then the approach you mentioned in point two could be a viable solution.
With the first option you can block the saving if the data is invalid - from within the SaveRecordRequest handler, if you don't call next?.handle(request) and instead just return false, then the save will be cancelled. In your case, you would perform the checks in the code and based on the result of them you would return false if they're invalid, or return the usual next?.handle(request) otherwise. You can combine this with showing a notification to the user or similar so they understand that the record hasn't saved & why. See this post for an example of cancelling the save (this one is for the progress bar/DCM stage change cancelling, but it works via the same mechanism): https://community.creatio.com/questions/freedom-ui-dcm-cancel-transitio…
Please advise what could be the problem. There is a business process where the start signal (trigger) is set to launch when the text field "CHErrorNotification" in Opportunity is changed. If I change the field manually, the process starts, BUT if I change it via code, nothing happens—the process doesn't start. As you can see in the examples, I'm changing it not through a query; the process should start.
I tried filling the field both during the save and after; in both cases, the field was populated, but the process trigger did not work. OnSaving OnSaved
Previously, and even now in other systems that I configured earlier, the process starts when such code changes occur. Regarding point 1, can you provide an example?
There are cases when a record is inserted directly from db and the bp doesn't trigger on object signal(Record Added/Modified), how do I proceed in these cases?
A direct database insert/update won't trigger a signal needed for a process to start. Only option I can think of is to flag the record in some way and have a process running on a timer looking for the flagged records.
if you have control over the insert/update process, you could set up a stored procedure in the DB and call it after the insert/update operation. The stored procedure could call the ProcessEngineService.svc via web request.
Can you provide more details on your custom code since I've created a simple method in the Account object that modifies a contact in the process inside the Account object (using onInserted method):
var contactEntity = UserConnection.EntitySchemaManager.GetInstanceByName("Contact");
var contactRecord = contactEntity.CreateEntity(UserConnection);
contactRecord.FetchFromDB("Id", new Guid("9c4111d2-cbf1-49f2-8c2b-00c6a82547c0"));
contactRecord.SetColumnValue("Name", "From the code");
contactRecord.Save();
and it triggers the business process with the start signal that is executed when the Contact name is modified. Maybe your logic is not modifying the record in the manner that should trigger the business process.
UsrContactSaved - the process on Contact schema that triggers when Contact record is saved ContactUtilities.ChangeContactStatus - the method that should change Status on schema Contact (this method is scheduled by job)
UsrOnContactStatusChanged - the process that should be triggered when the Status field in Contact schema was changed (but it doesn`t trigger)
So, when UsrContactSaved process triggered, there is a code in it that schedule a job that must call ContactUtilities.ChangeContactStatus in 10 minutes. After 10 minutes triggers ContactUtilities.ChangeContactStatus method and it changes Status via method in C# code.
In conclusion, status changed but UsrOnContactStatusChanged didn`t work. Expected result: UsrOnContactStatusChanged has to be triggered after work of UsrChangeContactStatusProcess process.