We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Restrict a type of state to only one item

LarissaR4486026
Tera Contributor

I wanted to know how I can make the Pending state appear only on a specific item without showing up on the others. Is that possible?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron

You can create an onLoad Client Script on whatever table you're referring to:

function onLoad() {
    if (g_form.getValue('cat_item') == '<sys_id of specific catalog item>') {
        g_form.removeOption('state', -5);
    }
}

Where cate_item is the name of the field that determines the 'specific item', and -5 is the value of the Pending choice.

View solution in original post

6 REPLIES 6

Brad Bowman
Kilo Patron

You can create an onLoad Client Script on whatever table you're referring to:

function onLoad() {
    if (g_form.getValue('cat_item') == '<sys_id of specific catalog item>') {
        g_form.removeOption('state', -5);
    }
}

Where cate_item is the name of the field that determines the 'specific item', and -5 is the value of the Pending choice.

Hello @Brad Bowman  ,

  I'm little bit  confused here , as per question he want to show pending state on specific item  except other item  so code should be ? 

 

function onLoad() {
    if (g_form.getValue('cat_item') != '<sys_id of specific catalog item>') {
        g_form.removeOption('state', -5);
    }

   Can you please confirm this ?

 

Thanks ,

Aditya

Yeah, I read it wrong - focused on the vagueness of the details provided, so != is what I meant.

PoonkodiS
Mega Sage

Hi @LarissaR4486026 @Brad Bowman  

If i am not wrong,they want to make a field appear only in specific catalog item. But, you add remove option

 

g_form.addOption('state', '5', '5 - Pending approval');

 

addOption(String fieldName, String choiceValue, String choiceLabel)

Adds a choice to the end of a choice list field.
 
-Poonkodi