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

Harish Bainsla
Kilo Patron
Kilo Patron

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}

var tickettype = g_form.getValue('type');
var approv = g_form.getValue('approval');

if (tickettype == "871c5d5e87b3e9140811646e8bbb3530" && approv == "not requested" && g_form.getValue("state") == "Resolved") {
alert("Hello world");
g_form.addErrorMessage("Status could not be changed");
g_form.setValue("state", "In progress");
alert("Status set to 'In progress'");
}
}

Hi @Harish Bainsla ,

 

I used similar code but from if condition it is not working. Not get any alert() from inside if loop.

please put backend resolved field value

Vicky Kumar Sh1
Tera Contributor

You are storing value in var ticket and in if condition using tickettype? Try changing it to ticket in if condtion?