Notification Approval

Poorva Bhawsar
Mega Sage

Hi Community,

 

I have a new state specific to a catalog item. I want to hide this new state, it should only be visible to a catalog item. Once this state is selected, it should trigger an approval to a group. If approved, need to change the state of the server ci from inbuilt to active. All SC tasks attachments needs to attach on the ci selected on the form.

 

I have this client script to hide this new state.

 

function onLoad() {
    var item = g_form.getValue('cat_item');
    if (item != 'a60987578739a514aa3574497bbb3533') {
        g_form.removeOption('state', 5);
    }

}
But its hiding this state option for all catalogs. I want to show this for a specific catalog item.
12 REPLIES 12

This is my latest script.

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

    var item = g_form.getValue('cat_item');
    if (item == 'a60987578739a514aa3574497bbb3533') {
        g_form.addOption('state', '-7', 'Pending Approval', '4');
    } else {
        g_form.removeOption('state', -7);
    }

}
 
I cant use onload client script for add/remove options. So, i need to use this onchange client script. Until i change the state of sctask to any other that option is visible and when i change it to any other it disappears. Basically sctask is in open state so definitely user will select work in progress first.
Any correction in this?

Also how to create approvals in workflow when user selects this xyz state on sc task? I need to add condition for this.

This is my script but its hiding it for this catalog item also.

 

 var item = g_form.getValue('cat_item');
    if (item == 'a60987578739a514aa3574497bbb3533') {
        g_form.addOption('state', '-7', 'Pending Approval', '4');
    } else {
        g_form.removeOption('state', -7);
    }
 
Is there any other option to add this new state only for this catalog item?

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Poorva Bhawsar 

 

 I want to hide this new state, it should only be visible to a catalog item.

My thought, dont hide, better put a validation, if a user select the state, got a popup message.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

I am using this script and its working fine.

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

    var item = g_form.getValue('cat_item');
    if (item == 'a60987578739a514aa3574497bbb3533') {
        g_form.addOption('state', '-7', 'Pending Approval', '4');
    } else {
        g_form.removeOption('state', -7);
    }

}
 
The only issue i am having is whenever an sc task created, state is open at that time this particular state is showing  once i change it to any other state it disappears.
 
I am using onchange client script. I am not using onload client script because we cant use add or remove option functions for onload client script. We need to use onchange only.
 
What i need to do in this case?