The CreatorCon Call for Content is officially open! Get started here.

Script - how to set a constant value for a var script? also some equation questions too.

alberttagle
Tera Contributor

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.

find_real_file.png

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!

19 REPLIES 19

Hi Brian

I changed the script to the you just suggested, however, it is still not working

find_real_file.png

Brian O_Donnell
Tera Guru

make sure you change all of your g_form.getvalue to g_form.getValue (cap V) and setvalue to setValue

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...

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.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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);
}