Client script

tushar_ghadage
Tera Contributor

Hi guys , 

 

State choice = Closed should be hidden from the form if State = new, for Change Tasks

 

for that I have written on load client script :

 

function onLoad() {
   //Type appropriate comment here, and begin script below
    g_form.addOption('state','3');

   if(g_form.getValue('state') == '1')
   {
    g_form.removeOption('state','3');
   }
}
its working but for other option too showing the choice ' closed 'hidden ..
 
any correction guys I  need to make??
 
thankss !!
12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@tushar_ghadage 

script from @Chaitanya ILCR should work

what debugging did you do?

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

as you can see in the SS 

option is getting removed but its not getting added when open choice is unselected : 

below is the script :

function onLoad() {
   //Type appropriate comment here, and begin script below
   

    // Then, if state is 'New', remove it
    g_form.addInfoMessage('checking one');
    if (g_form.getValue('state') === '1') {

        g_form.addInfoMessage('checking 2');
        g_form.removeOption('state', '3');
    }
    else
    {
        g_form.addInfoMessage('checking 3');
        g_form.addOption('state', '3', 'Closed');
    }
Screenshot (174).png

Hi @tushar_ghadage ,

 

for whatever your trying to do you require an onchange client script

update you client script as below

ChaitanyaILCR_0-1750850333970.png

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading) {
        if (newValue == '1')
            g_form.removeOption('state', '3');
        return;
    }

    if (newValue == '1')
        g_form.removeOption('state', '3');
    else {
        g_form.addOption('state', '3', 'Closed',3)
    }

}

 

but the approach is wrong

with this the purpose of removing closed state on open change is of no use as users can select anyother value to make closed to appear on a open change tasks and select the close directly where the state of change task is still open 

 

they have to save the form first with their option 

 

 

you have to go with the onload client script here in this scenario(you can refer my first response for that)

 

but this is what you want update your client script as mentioned

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya