g_form.setValue() within an IF statement

patricklatella
Mega Sage

hi all,

I'm using an IF activity within a workflow to determine a time value for a variable on a requested item.   If my time variable is greater than a certain number I need to set the value of a variable on the requested item to "TRUE".   However I'm getting errors when simply putting in a setValue statement.   Anyone see my error?   thanks!

if (diffSeconds > 1209600) { //startDate is more than 2 weeks away from the nowDate

var pause = current.variables["u_pause_sla"];//this is the variable on the sc_req_table I want to set to true if my "if" statement is met

g_form.setValue(pause, true);

return 'yes';

}

else {

return 'no';

}

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Patrick,



g_form is a client side method and only available in a client script or ui policy on a form rather than in a workflow. Also, I think it's a better practice to separate out setting values from the if statement. I would add a run script workflow activity on the yes branch after the if activity that sets the variable to true using the current object.


View solution in original post

5 REPLIES 5

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Patrick,



g_form is a client side method and only available in a client script or ui policy on a form rather than in a workflow. Also, I think it's a better practice to separate out setting values from the if statement. I would add a run script workflow activity on the yes branch after the if activity that sets the variable to true using the current object.


thanks Brad, will do!


SanjivMeher
Kilo Patron
Kilo Patron

Hi Patrick,



Instead of using client script, do it using business rule.



Write an update onBefore business Rule



current.variables.u_pause_sla = true;




Please mark this response as correct or helpful if it assisted you with your question.

thanks Sanjiv,


I'm gonna go with a Set Values activity in the workflow.