show/hide dropdown options from the state field on lifecycle event case table

Ediga Sai Chand
Tera Contributor

Hello Team ,

 

I have a state field with options like draft , ready , work in progress , and 3 other fields . When a case is created it is automatically setting the state to draft state by using client script . My requirement is to hide all the other options when the case is on draft state and show only ready state and hide all the other options and make the state field readonly.

1 ACCEPTED SOLUTION

jaheerhattiwale
Mega Sage
Mega Sage

@Ediga Sai Chand Create a new onload Client script on your table and add below code to it.

 

function onLoad() {
if (g_form.isNewRecord())
return;

var DRAFT = "1"; //Draft state value
var READY = "10";
var WORK_IN_PROGRESS = "18";
//Add other 3 state choice and values here as below
var FOURTH_CHOICE = "";
var FIFTH_CHOICE = "";
var SIXTH_CHOICE = "";

if (g_form.getValue("state") == DRAFT) {
g_form.removeOption("state", FOURTH_CHOICE);
g_form.removeOption("state", FIFTH_CHOICE);
g_form.removeOption("state", SIXTH_CHOICE);
}
}

 

Note: Add correct choice values for other 3 options in script

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

2 REPLIES 2

Naga Ravindra R
Kilo Sage

Hi @Ediga Sai Chand 

 

You need to tweak the OOB client script "Restrict state changes".

 

Or you can create a separate one by following the about client script, which has to be valid only for Lifecycle events cases.


var REMOVE_DRAFT_TRANSITIONS = [AWAITING_APPROVAL, WORK_IN_PROGRESS, AWAITING_ACCEPTANCE];  //in this line you have to keep only Ready for work.

 

Please mark as correct/helpful if it helps.

 

 

jaheerhattiwale
Mega Sage
Mega Sage

@Ediga Sai Chand Create a new onload Client script on your table and add below code to it.

 

function onLoad() {
if (g_form.isNewRecord())
return;

var DRAFT = "1"; //Draft state value
var READY = "10";
var WORK_IN_PROGRESS = "18";
//Add other 3 state choice and values here as below
var FOURTH_CHOICE = "";
var FIFTH_CHOICE = "";
var SIXTH_CHOICE = "";

if (g_form.getValue("state") == DRAFT) {
g_form.removeOption("state", FOURTH_CHOICE);
g_form.removeOption("state", FIFTH_CHOICE);
g_form.removeOption("state", SIXTH_CHOICE);
}
}

 

Note: Add correct choice values for other 3 options in script

 

Please mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023