Expand my Community achievements bar.

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

Modification of a javascript for calculating a total

Avatar

Level 2

Hello Experts,

I have a form that uses the following javascript to calculate a total:

this.rawValue = Qty1.rawValue * UnitPrice1.rawValue * Calc1.rawValue ;

The script works fine, but I am looking for another option where I can also enter just the value in the "Total" field (and leave the qty, unit price, calc fields blank).

I tried to set the "Total" field's value type to "User Entered - Optional" or "Calculated - User Can Override", but the Total field will still not populate (still needs the other fields populated).

Is there a setting in the Total field that I am not applying correctly, or is there a different javascript that I can use to get both the calculated option and the Total only option?

I have attached an example of a form containing the calculation:

https://acrobat.com/#d=YpsugiCU4JiAMiQ0w6FCuQ

As always, I appreciate all of the assistance that is offered on this forum.

Thanks,

Eric

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi Eric,

You can try the following.

Remove the script in the calculate event of the Total field. Rather keep it in any event. Lets say click event.

Then in the exit event of the UOM dropdown event write an if condition whether the fields  - Qty,UnitCost has any value or not. If yes, call the event that you have written in the click event which actually calculates.

If the above fields has no vale then you can simply blan out the else part.

For ex: In the exit event of the UOM dropdown.

form1.P1.ItemSet.UOM1::exit - (JavaScript, client)

if(!(Qty1.rawValue == null || UnitPrice1.rawValue == null || this.rawValue == null))

    {

        form1.P1.ItemSet.LineTotal1.execEvent("click");

    }

else

    {

    }       

In the click event of the total field you can write : this.rawValue = Qty1.rawValue * UnitPrice1.rawValue * Calc1.rawValue ;

Hope it helps.

Thanks,

Bibhu.

View solution in original post

2 Replies

Avatar

Correct answer by
Level 9

Hi Eric,

You can try the following.

Remove the script in the calculate event of the Total field. Rather keep it in any event. Lets say click event.

Then in the exit event of the UOM dropdown event write an if condition whether the fields  - Qty,UnitCost has any value or not. If yes, call the event that you have written in the click event which actually calculates.

If the above fields has no vale then you can simply blan out the else part.

For ex: In the exit event of the UOM dropdown.

form1.P1.ItemSet.UOM1::exit - (JavaScript, client)

if(!(Qty1.rawValue == null || UnitPrice1.rawValue == null || this.rawValue == null))

    {

        form1.P1.ItemSet.LineTotal1.execEvent("click");

    }

else

    {

    }       

In the click event of the total field you can write : this.rawValue = Qty1.rawValue * UnitPrice1.rawValue * Calc1.rawValue ;

Hope it helps.

Thanks,

Bibhu.

Avatar

Level 2

Hi Bibhu,

Your solution worked perfectly.

Thank you very much.

Eric