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

how to set value using g_form.setvalue()

JA8
Kilo Contributor

function onSubmit() {
//Type appropriate comment here, and begin script below

var a=g_form.getValue("state");
var b=g_form.getValue("hold_reason");
if(a==3 && b!='')
{
g_form.setValue("state", 4);
g_form.setValue('hold_reason',b);

here the value of  ' b' is becoming null .any suggestions

 

3 REPLIES 3

EdwinCoronado
ServiceNow Employee
ServiceNow Employee

looks like you're missing an '{' in the end. Should be:

 

var a = g_form.getValue("state");
var b = g_form.getValue("hold_reason");
if(a==3 && b != '') {
g_form.setValue("state", 4);
g_form.setValue('hold_reason', b);
}

chandrakanth2
Kilo Explorer

what will be for multiplication and adition 

Vamsi Sreenivas
Tera Guru

Place below alert code before if statement line and observe if hold_reason is really having a value.

alert("Value of b is " + b);

 

And I believe hold_reason field is displayed on the form because g_form.getValue() WORKS only if field is on the form.