Hi Creatio community,

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!

Thanks in advance!

Like 1

Like

5 comments

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.

Harvey Adcock,

Thanks for your input Harvey,

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?

A couple of thoughts:

  1. Could the checking be done on record save rather than whenever the data is changed? In which case, the following guide is useful: https://customerfx.com/article/adding-code-to-the-save-event-of-a-creatio-freedom-ui-page/
  2. 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?

Harvey Adcock,

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.

Thanks Harvey! 

Valerie Bsereni,

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…

But glad I could help!

Show all comments

Hi community..

 

I'm using a marketplace add-on, and want to customize one of their page.

In that page, there is a button that implement a custom handler. And how to modify/override that custom handler in my custom package?

For that page i have make it available in my custom package, but when i switch to code (client schema) i didn't find that handler.

Is it possible?

Like 0

Like

6 comments

You won't see the handler in your replacing page, however, you can still override it. For example, if the base page has a request called this: 

{
	request: "usr.MyCustomRequest",
	handler: async (request, next) => {
		// code is here
 
		return request?.handle(next);
	}
}

In your code in the replacing page, you could add:

{
	request: "usr.MyCustomRequest",
	handler: async (request, next) => {
		// YOUR code here, as needed
 
		// the line below calls the base page's handler
		return request?.handle(next);
	}
}

If you don't want the base page's handler to run, just omit the line below in your code:

return request?.handle(next);

Then with that line gone in your handler in the replacing page, the base page's handler won't run at all since it won't get called. If you still want it to run, but then your code does other stuff after it is done, you could do this: 

{
	request: "usr.MyCustomRequest",
	handler: async (request, next) => {
		// let base page handler run first
		const result = await request?.handle(next);
 
		// now do your stuff
 
		return result;
	}
}

Hopefully, that makes sense.

Ryan

Hi Ryan,


Thanks for the response..

 

I tried that and the good news is I can change the handler (it works), but the parent handler is still called 🥲

 

{
handlers: /**SCHEMA_HANDLERS*/[{
				request: "crt.CloseChatRequest",
				handler: async (request, next) => {
					const chatId = request.recordId;
					const category = request.category;
					let categoryId;
 
					console.log({chatId, category,categoryId});
 
					// return request?.handle(next);
				}	
		}]/**SCHEMA_HANDLERS*/
}

 

As you can see, it is related to closing the chat. 

In my code, I do nothing except just to console log. 

The expectation is that the chat session is not closed, but the result is that it is still closed.

 

Am I missing something?

Cokky Saut Monang Turnip,

Hmm. Try returning false? (instead of just commenting out the return request.handle(next))

In order to customize a page from a marketplace add-on and override a custom handler in your custom package you can do the following:

  1. Create a new client schema in your custom package (e.g., CustomPageSchema).
  2. Extend the existing schema and override the handler:
define("CustomPageSchema", ["OriginalPageSchema"], function() {
    return {
        entitySchemaName: "YourEntitySchemaName",
        attributes: {},
        diff: [],
        methods: {
            // Override the custom handler
            onButtonClick: function() {
                // Your custom logic here
                console.log("Custom handler logic");
 
                // Optionally, call the base method if needed
                this.callParent(arguments);
            }
        }
    };
});
  1. Register the custom schema in the CustomPageSchema schema.

After that deploy your changes and test.

 

Also if you don't want to create a new schema you can try to update the existing one.

     1. Add new handler method in the method section:

 

methods: {
	onButtonClick: function() {  }
}

     
2.Bind the new method to "click" event of the corresponding   button

 

   diff: /**SCHEMA_DIFF*/[
	{
		"operation": "insert",
		"name": "YourButton",
		"values": {
		"itemType": 5,
		"caption": {
			"bindTo": "Resources.Strings.YourButtonCaption"
		},
		"click": {
			"bindTo": "onButtonClick"
		},
		...
	}
		...
]


 

Also you can find some useful information in this article

https://customerfx.com/article/overriding-modules-in-creatio-formerly-b…

Iryna Oriyenko,

That applies to classic pages (and modules) only, not Freedom UI page handlers.

Ryan Farley,

Negative.. the result is still same 🥲🥲

 

I have tried :

  • - return true;
  • - return false;
  • - comment out the 'return request?.handle(next);'

 

any clue??

Show all comments

deleted

Like 0

Like

2 comments

Hello Agnieszka,

To fix the issue you should change the property: 

1) sdk.ComparisonType.LessOrEqual to sdk.ComparisonType.Less_or_equal   

2) sdk.ComparisonType.GreaterOrEqual to sdk.ComparisonType.Greater_or_equal

Good practice is to check if the property exists with the console:

Anhelina,

Thank you

Show all comments