FreedomUI - How can I calculate a set of fields right after loading the form page?

Hi Community,

 

I have this business requirement, where I need to calculate my "Monthly Total" field right after I finish loading my form page.

 

These are the formula and fields I want to calculate:

 

var total = (monthlySubTotal - discountAmount) + ((monthlySubTotal - discountAmount) * (taxRate / 100));

 

 

I tried to use "crt.HandleViewModelInitRequest" handler, but it didn't work. Because, the data is not fully loaded.

 

Is there any other handler that I can use, that waits for all the data to be loaded and then calculate my formula?

 

Thanks in advance.

 

Best Regards,

Pedro Pinheiro

 

 

 

 

 

Like 1

Like

4 comments
Best reply

 Hello. Try this.

{
	request: "crt.HandleViewModelAttributeChangeRequest",
	handler: async (request, next) => {
		if (request.attributeName === "UsrFirstField" || request.attributeName === "UsrSecondField") {
			//recalc
		}
		return next?.handle(request);
	}
}

 

 Hello. Try this.

{
	request: "crt.HandleViewModelAttributeChangeRequest",
	handler: async (request, next) => {
		if (request.attributeName === "UsrFirstField" || request.attributeName === "UsrSecondField") {
			//recalc
		}
		return next?.handle(request);
	}
}

 

Alex Zaslavsky,

 

Thank you for  the reply.

 

I'm using the "crt.HandleViewModelAttributeChangeRequest" handler when a field is being changed.



However, in this situation, the field does not receive any change. For example, the "Tax Rate, %" field has 15.00 as its default value. This does not trigger the "crt.HandleViewModelAttributeChangeRequest" handler. But I need it to calculate the "Monthly Total" field.



After some research, I found the "crt.LoadDataRequest" handler. This handler is executed after all the data has been loaded. So, for the moment, it's working for our requirement.

 

Best Regards,

Pedro Pinheiro

I think your "Tax Rate" field triggers this request, but it's silent.

request.silent

 

Alex Zaslavsky,

 

I've changed the solution and now it's working with the "crt.HandleViewModelAttributeChangeRequest" handler.

 

Thank you.

 

Best Regards,

Pedro Pinheiro

Show all comments