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

On-change Client script issue in ServiceNow

abirakundu23
Mega Sage

Hi All,

I wrote one client script on change based on the if condition status could not be change & its will through info/error message & status will back to "in progress" state instead of changing any status. 

But for when we select "Resolved" , inside the if loop is not executed & alert message not executed.

Regarding this request instead of adding this condition : if (tickettype == "871c5d5e87b3e9140811646e8bbb3530" && approv == "not requested" && g_form.getValue("state") != "In progress") to if (tickettype == "871c5d5e87b3e9140811646e8bbb3530" && approv == "not requested" && g_form.getValue("state") == "Resolved") not working properly after if loop, within if loop alert not display. could you please help me on that.

 

 
 
   //Type appropriate comment here, and begin script below
 
 
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
   //Type appropriate comment here, and begin script below
var ticket = g_form.getValue('type');
alert(ticket);
var approv = g_form.getValue('approval');
alert(approv);
if (tickettype == "871c5d5e87b3e9140811646e8bbb3530" && approv == "not requested" && g_form.getValue("state") == "Resolved")
 
{
alert("Hello world");
g_form.addErrorMessage("status could not change");
g_form.setValue("state","In progress");
alert("Hello world123");
}
}

 

 

 

 

7 REPLIES 7

Hi @Vicky Kumar Sh1 , I have changed but it is not working from if condition. No alert() message is not executing.

Try alerting all the value first. And one more issue I can see is that you are checking getValue('state')=='Resolved')
Check with backend value of resolved. It is 6. getValue('state')=='6' or getValue('state')==6

Add a line containing debugger; in front of line var tickettype = g_form.getValue('type');

 

Use developer tools in your browser to check if all values contain what you expect.


Help others to find a correct solution by marking the appropriate response as accepted solution and helpful.