Hi All,
I would like to sum the values of two fields, for example: Field A + Field B = Field C.
How do I configure Field C to perform this calculation?
Thanks
Like
It depends on what exactly you need. If you want to take a value from one field, perform an arithmetic operation with field B, and store the result in field C when the value in the first field is specified, you should follow the approach described in this article: https://customerfx.com/article/responding-to-an-event-when-a-field-is-changed-on-a-creatio-freedom-ui-page/, assigning the value as explained in this article: https://customerfx.com/article/programmatically-determining-the-bound-attribute-for-an-object-property-in-a-creatio-freedom-ui-page/.
Oleksandr Tyra,
Hi,
thanks for your answer, sorry but i still confused, For example, I input field a is 1000 and field b is 2000, for field c will be filled automatically by adding field a and b to 3000, is that possible? And what is the step?
thanks
muhammad rizky,
Hello,
as of version 8.2.2, you can use the new business rule formula feature of the "set field value" action.
Before that, you would either create a business process that does the calculation (if live updates are enabled on the entity, the result will immediately show up on the form after saving), or programmatically, as Oleksandr has described it.
muhammad rizky,
{ request: "crt.HandleViewModelAttributeChangeRequest", handler: async (request, next) => { // listen for changes to the EmployeesNumber field if ((request.attributeName === "UsrStringField_A" || request.attributeName === "UsrStringField_B") && !request.silent) { //var fieldA = request.$context.getAttributeNameByViewItemName("UsrStringField_A"); -- or like this //var fieldB = request.$context.getAttributeNameByViewItemName("UsrStringField_B"); -- or like this const fieldA = await request.$context.UsrStringField_A; const fieldB = await request.$context.UsrStringField_B; request.$context.UsrStringField = fieldA + fieldB; } return next?.handle(request); } }
Oleksandr Tyra, Robert Pordes,
Thanks for your advices, i will try it first