Expand my Community achievements bar.

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

Scripting Help

Avatar

Level 1

Could someone please convert the excel formula below into Formscript or Javascript language for me? Sorry, but I've run out of patience.

=((([Cellname]-TRUNC([Cellname]))/60)*100)+TRUNC([Cellname])

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

You could also try the following.

Set up a decimal field (different from a numeric field) for the user to input the number. Call this "input"

Then set up a second field to do the calculation and spit out the answer; call this "output".

In the script I have used variables (instead of invisible fields). These hold interim results for the duration of the script.

This is FormCalc:

var inputNr = input   // sets the variable inputNr as the full number the user inputted

var inputTrunc = Floor(inputNr)   // truncates the number to an integer without rounding

$ = ((inputNr - inputTrunc) / 60)*100 + inputTrunc    // does the calculation you want

Hope that helps,

Niall

View solution in original post

4 Replies

Avatar

Level 4

I made 4 fields, 2 visible and 2 invisible

Field 1: User enters Data

Field 2: invisible; calculated: Dezimalfield1 * 1; with no aftercommas (right pannel)

Field 3: (this is the [Cellname]-TRUNC([Cellname]): invisible; calculated: Dezimalfield1 - Dezimalfield2

Field 3: validate (javascript)

if (this.rawValue < 0)
{this.rawValue = this.rawValue + 1}
else {true;}

Field 4 (Solution): calculated: Dezimalfield3 *100 / 60 + Dezimalfield1 - Dezimalfield3

Hope you are alright with this one too, though it's quite complicated

Message was edited by: ocen12

Delte the text of the Decimalfield4 calculate and use instead on validate:


if (this.rawValue == Dezimalfield3.rawValue *100 / 60 + Dezimalfield1.rawValue - Dezimalfield3.rawValue)
{true;}
else
{this.rawValue = Dezimalfield3.rawValue *100 / 60 + Dezimalfield1.rawValue - Dezimalfield3.rawValue;}

Reason: it took the values of Decimalfield3 before validation. The values I tried worked...
(Learned another thing. Calculated fields populate with not validated values.)

Avatar

Correct answer by
Level 10

Hi,

You could also try the following.

Set up a decimal field (different from a numeric field) for the user to input the number. Call this "input"

Then set up a second field to do the calculation and spit out the answer; call this "output".

In the script I have used variables (instead of invisible fields). These hold interim results for the duration of the script.

This is FormCalc:

var inputNr = input   // sets the variable inputNr as the full number the user inputted

var inputTrunc = Floor(inputNr)   // truncates the number to an integer without rounding

$ = ((inputNr - inputTrunc) / 60)*100 + inputTrunc    // does the calculation you want

Hope that helps,

Niall

Avatar

Level 1

Thanks very much for that. I went with Niall's solution.

Here's another couple though:

=TRUNC([Cellname]/60)+([Cellname]-TRUNC([Cellname]/60))*60)/100)

=([Cellname]-TRUNC[Cellname])*100+TRUNC[Cellname]*60