OnLoad client script

tushar_ghadage
Tera Contributor

Hi @all

Here I am hiding the choice called "closed" on change task only when change request is in new state.

for this I had below on load client script on change task: 

 

function onLoad() {
g_form.getReference('change_request', function(ref) {
if (ref) {
var parentState = ref.state;
if (parentState === '1') {
g_form.removeOption('state', '3');
} else {
g_form.addOption('state', '3', 'Closed');
}
}
});
 
but its closed is showing up
 
could anyone please clarify what's wrong 
 
thanks!!
 
 
 
1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

A Change request in the state of "New" translates to the value "-5"
Please try and see if it helps.

View solution in original post

3 REPLIES 3

OlaN
Giga Sage
Giga Sage

Hi,

A Change request in the state of "New" translates to the value "-5"
Please try and see if it helps.

thanks for pointing out it worked

Ankur Bawiskar
Tera Patron
Tera Patron

@tushar_ghadage 

It should be available by default, so just remove it and don't add the choice

also New state means -5

try this

function onLoad() {
    g_form.getReference('change_request', function(ref) {
        if (ref) {
            var parentState = ref.state;
            if (parentState.toString() == '-5') {
                g_form.removeOption('state', '3');
            }
        }
    });
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader