calculations based on drop down and predefined values
Copy link to clipboard
Copied
Hello,
Below is my query.
I have one drop-down to select the market
one more drop-down to select the item.
A text field displays the value based on these two selections.
also a text field to enter Qty.
Another text field for discount.
One more read-only text field displays the final price based on the first text field considering the Qty and the discount.
I need to show the profit as well.
Considering all the above, How do I do that.
Example of the query. (I am no JS expert, Apologies in advance)
If Market is UAE - ECP, Profit = Offered Price - (Predefined Value * Qty)
I was thinking of something like below.
var mkt = this.getField("DP2").value;
var sell= this.getField(("Text44").value;
var p1= Text32*1000
if (mkt=="UAE - ECP") event.value = sell-p1
Please help me out. I am clueless.
Copy link to clipboard
Copied
The first thing you should do is to use meaningful names for form fields and variables. You may know what Text44 is, but nobody else who might have to work on this form would know that, and there is a pretty good chance that when you put this form aside for a couple of weeks, by the time you come back, you will no longer remberer that bit of information.
You are on the right track (that is as long as your variables are set correctly). This is what you have today:
var mkt = this.getField("DP2").value;
var sell= this.getField(("Text44").value;
var p1= Text32*1000
if (mkt=="UAE - ECP") event.value = sell-p1
This assumes that it's the calculation script for the result field (otherwise "event.value" will not work for that field). There are a few problems with your code. There is a pretty good chance that the JavaScript editor tried to alert you about some of them, and the JavaScript debugger about the remaining ones.
Your first line is correct, the second line has an extras "(", once you remove that, it will also work. The third line is trying to access something called "Text32", based on the other field with a similar name ("Text44"), I assume it's a form field as well. You need to again use the this.getField("someFieldName").value syntact to get it's value. Once you do that, the script should work:
var mkt = this.getField("DP2").value;
var sell= this.getField("Text44").value;
var p1= this.getField("Text32").value*1000;
if (mkt == "UAE - ECP") {
event.value = sell-p1;
}
I've added some more structure to make the script easier to read.

