Skip to main content
Participant
May 1, 2024
Question

Need Script Help For Conditionals

  • May 1, 2024
  • 1 reply
  • 581 views

Good evening,

I have been working on this tiny script for days with little success.
I am working on a mileage reimbursement form. My job is in Finance - I am not a programmer by any means. My team has been using an inherited Excel form from 1996, and would prefer the e-signature ability of the Adobe forms our staff are used to using. I could do what I'm trying to do if I added a subtotal field, but I'm trying to minimize.


Person will enter their usual commute mileage (text field name = Commute)
They will check a box if their trip includes mileage to or from their home. (checkbox name = HomeR1)
They will check a box i f theyr mileage is round trip. (checkbox name = RTR1)

The subtotal mileage for the trip is entered (text field name = MiR1)

Now the final field is Total Miles (TtlR1) I want this value to show MiR1 minus the commute mileage (Commute) if the (HomeR1) checkbox is selected, or subtract 0/stay the same if the box is unmarked. THEN I would like it to double if the (RTR1) checkbox is selected for round trip.

I am able to get the subtracting or the doubling (see code), but if both boxes are checked it's not taking the deduction twice...

var newValue = 0;
if (this.getField("HomeR1").value!="Off")
  newValue -= Number(this.getField("Commute").value);
if (this.getField("RTR1").value!="Off")
  newValue += Number(this.getField("MiR1").value*2);
event.value = newValue;

I'm both embarassed and frustrated because it feels like it should be not be so difficult - I am very strong in Excel, and have been working in PowerBI but this is escaping me.
I appreciate any advice or assitance, thank you for your time, and I apologize for the novel: was trying to be clear.

This topic has been closed for replies.

1 reply

ls_rbls
Community Expert
Community Expert
May 2, 2024

Hi @Stella37121326f1r1 ,

 

Would you mind sharing the formula that you had in Microsoft Exel?

 

Or better yet, are you able to share a dummy copy of the .xls file with the working formula to see how it actually works and behaves on the spreadsheet?

 

 

 

 

Participant
May 2, 2024

Hello, 
Unfortunately the Excel document uses a subtotal column: it doesn't combine both selections. That's going to be my functional solution, but it's not as elegant as I had hoped to have 🙂
Honestly I was tasked with making the exact form in Adobe, which is simple enough but it's so clunky I thought it would be simpler to combine!