Add Code to When the View Model is Initialized (or the Equivalent of the onEntityInitialized Function) in a Creatio Freedom UI Page

In Creatio classic pages, you could add a function called onEntityInitialized to perform things when an edit page loads and the data is available to access. In Freedom UI pages, to do the same, you need to wire up a handler for the crt.HandleViewModelInitRequest.

To add code to the page that will fire when the page’s model/data is available and ready, simply add the following to the page’s handlers:

{
	request: "crt.HandleViewModelInitRequest",
	handler: async (request, next) => {
		// allow base page initialization to complete
		await next?.handle(request);
		
		// add any custom code here
	}
}

This is the equivalent to the onEntityInitialized in a Freedom UI page. In this handler, you can also to things you’re used to doing in classic Creatio pages as well. For example, check if the page is for and “add” or “copy”:

{
	request: "crt.HandleViewModelInitRequest",
	handler: async (request, next) => {
		await next?.handle(request);
		
		const cardState = await request.$context.CardState;
		if (cardState == "add" || cardState == "copy") {
			// do something here
		}
	}
}

Additionally, any field/attribute values from the page can be accessed via the request.$context.

ABOUT THE AUTHOR

Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of slxdeveloper.com. He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!