On-change Client script in Loop in Servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2023 12:44 AM - edited 08-11-2023 12:50 AM
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.
Info/Error message not showing & alert is showing as a loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 03:17 AM - edited 08-21-2023 05:19 AM
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var tickettype = g_form.getValue('ticket_type');
alert(tickettype);
var approv = g_form.getValue('approval');
alert(approv);
var st = g_form.getValue("state");
alert(st);
if (tickettype == "871c5d5e87b3e9140811646e8bbb3530" && approv == "not requested" && g_form.getValue("state") == "Resolved")
{
alert("Hello world");
g_form.addErrorMessage("Status should not change");
g_form.setValue("state","In progress");
alert("Hello world123");
}
}
Initially it was worked for when we put 3rd condition g_form.getValue(state) != "In Progress" but some requirement we want to change g_form.getvalue(state) =="Resolved" but within if loop no alert is working. can you help me on that ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-21-2023 06:14 AM
Hi @SwarnadeepNandy,