Skip to main content
August 20, 2020
Answered

Help w/drop down menu's and calculations

  • August 20, 2020
  • 1 reply
  • 3176 views

I'm creating a form for our company.  I have a set of drop down menu's with different services named Services 1 and so on.  With those, I have them set to export a value based on the selection and that goes to another drop down next to it, SA1.  SA1 is set for a  custom calculation script "event.value = this.getField("Services 1").valueAsString;". One of my selections requires a calcuation but I don't know how to do it automatically. For instance, in my first drop down "Services 1", I want one of the selections to multiply a number from another text field "Size" by 15 and have the total in SA1.  Is this possible? I can make the 2nd set of drop downs (SA1) a text field instead, it doesn't have to be another drop down.  

Thanks everyone

This topic has been closed for replies.
Correct answer ls_rbls

ls_rbls,  I wasn't able to implement that.  Where would I combine it with the other formula for the SA fields?  We have this already

"

event.value = this.getField("Services 2").value;


if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));
if (this.getField("Services 2").valueAsString == "Shrink Wrap Wide") event.value =
util.printf("$%,0.2f", (this.getField("Total Size").value * 17));

"


Combine it like this:

 

if (event.name&&event.source.name =="Services 2") {

event.value =  this.getField("Services 2").value;

if (this.getField("Services 2").valueAsString == "Shrink Wrap") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 15));

else if (this.getField("Services 2").valueAsString == "Shrink Wrap Wide") event.value = util.printf("$%,0.2f", (this.getField("Total Size").value * 17));

}

 

Copy and paste the code in all of the calculataed "SA" fields..  And don't forget to change the number in the "Services 2"  to the corresponding "Services" field number

1 reply

ls_rbls
Community Expert
Community Expert
August 20, 2020

+++EDITED REPLY,  I made an error and didn't inlcude a second part to the original reply.

 

Yes that is possible. 

 

You need to include a condition with (IF /ELSE ) statement(s) in your custom calculation script in order  to perform the appropraite multiplication when the desired selection is made at "Selection 1" dropdown.

 

It would look something similar to this and this will only get the face value of the "Services 1" dropdown menu:

 

 

 

if (this.getField("Services 1").valueAsString=="mySelection") {
event.value = this.getField("myOtherField").value * 15;
}

else event.value = this.getField("Services 1").valueAsString;


 

 

Now, be advised that when you use "valueAsString' to get a value from a dropdown menu it will not get the export values that you've assigned for each listed item.  Using the get method for a valueAsString will only get the face value of the selected item (the value as it appears to the user), not the export value.

 

If you really need to work with the export value of a a listed item that was selected from a dropdown menu, you'll need to modify the script above similar to this:

 

 

if (this.getField("Services 1").valueAsString =="mySelection") {

var f = this.getField("Services 1").currentValueIndices;
if (typeof f == "number") event.value = f.getItemAt(a,true)*15;
}
else event.value = this.getField("Services 1").valueAsString;

 

 

August 21, 2020

Thanks for your help.  I wasn't able to get either to work for me, but I don't know how to edit the 2nd.  In my first drop down I have the list of services we offer.  Everything has a set price except one item, Shrink Wrap.  This is the one I'm having trouble with because it's based off another value "TotalSize" mutiplied by 15.  There is a set of drop downs next to the first set with prices listed for the corresponding services.  I did it this way at first because I didn't know how the export values worked. 

Nesa Nurani
Community Expert
Community Expert
August 21, 2020

If I got it right you want to give "Shrink Wrap" value from "TotalSize"*15?

If yes then you can try incorporate this into your calculations:

var a = this.getField("TotalSize").value;
var b = this.getField("SA1").value;
var x = a*15;
if(b == "Shrink Wrap"){
event.value = x;
}

Or if you still have issue try sharing your file so we can see whats going on.