Script - how to set a constant value for a var script? also some equation questions too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 04:15 AM
Hi,
I'm not entirely sure where to look on why this script is not working. I have very limited knowledge on scripting, but will get some education very soon, yet I have a deadline coming up for this. Hope someone can help.
RED BOX: I'm trying to set a constant value for each VAR I created. Is this done correctly? or it needs some other scripting?
GREEN BOX: The value which will be input manually in a single text field, will always be divided by 1024, so I'm trying to come up with a VAR for it. Can I script it like this?
BLUE BOX: here, I placed the "equation" in the script, so the output will be in the 'price' variable.
Maybe I'm doing the entire script too simple, and apparently wrong.
Please help.
Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 06:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 07:09 AM
make sure you change all of your g_form.getvalue to g_form.getValue (cap V) and setvalue to setValue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 10:22 AM
Already did that, the first one who replied suggested it and I already did change all of the getValue and setValue.
I wonder what could I be missing...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 11:45 AM
try setting the value of the other field outside of that if block, then you can see if the math is right at least.
The other thing here is that I was assuming that this is a client script - is that correct? If this is a business rule, then you have to do it differently. and if it is a client script, you can simply use
alert('IronA = ' + IronA);
to throw a pop-up window to see what you have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2018 12:02 PM
JavaScript is case sensitive and I suspect that your values may be low yet your code is looking for Low. I find all your variables difficult to read so I modified part of your code, try this after declaring your pricing variables:
var DBSV = parseInt(g_form.getValue("sizeforcomputation"), 10) / 1024;
var env = g_form.getValue("whateventforpricing").toLowerCase();
var crit = g_form.getValue("criticalitytypeforpricing").toLowerCase();
if ((env == "development") || (env == "development" && crit == "medium") || (env == "test" && crit == "low")) {
var newPrice = (IronA * DBSV) + IronB;
g_form.setValue("price", newPrice);
}