Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Field Calculation

Avatar

Level 2

Hi,

I have created a Decimal field on a layout. I then have two other Decimal fields that are getting populated from the system. I want to try and subtract these two fields. I have been trying JavaScript and Formcalc, but cannot get it to work. It seems like it should be something easy to do. I would like to put this calculation on the "calculate" event.

First Field -> data.Page1.Position.ITEMS.TOTAL[0]

Field Subtracted from First -> data.Page1.Position.ITEMS.SALE

Calculation field -> data.Page1.Position.ITEMS.NEW

Any ideas how this can be done, or if it can?

Then I would like to hide the field if the calculated value comes back as zero, or empty. So I was going to try on the "initialize" event to add,

var new = data.Page1.Position.ITEMS.NEW.rawValue;

if (new == null || new == "" || '0')

{

   data.Page1.Position.ITEMS.NEW.presence = "hidden";

}

Any advice would be appreciated.

1 Accepted Solution

Avatar

Correct answer by
Level 7

Formcalc should be easiest if you are just subtracting fields to get an answer in another.

In the NEW calculate event it is simple as:

TOTAL - SALE

Thats all you need. As figures are changed in the TOTAL and SALE fields, the NEW field will update dynamically. It will also be automatically changed to read only so it cant be modified.

Hiding the field will need to be done in the field itself. It will only initialise when the form opens. If you want it to hide dynamically with the field's rawValue, put it into the calculation event also.

Note you will need to change your syntax for the formcalc if statement...or sometimes i put my javascript code separate hidden button and then programattically click a button.

You might need to account for getting the hidden field back as well if it isnt zero with an else on your if statement.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 7

Formcalc should be easiest if you are just subtracting fields to get an answer in another.

In the NEW calculate event it is simple as:

TOTAL - SALE

Thats all you need. As figures are changed in the TOTAL and SALE fields, the NEW field will update dynamically. It will also be automatically changed to read only so it cant be modified.

Hiding the field will need to be done in the field itself. It will only initialise when the form opens. If you want it to hide dynamically with the field's rawValue, put it into the calculation event also.

Note you will need to change your syntax for the formcalc if statement...or sometimes i put my javascript code separate hidden button and then programattically click a button.

You might need to account for getting the hidden field back as well if it isnt zero with an else on your if statement.

Avatar

Level 2

Sorry for the delay. That helped out a lot.

Thanks again,
Andrew