RemoveOption onLoad Client Script

brown9394
Tera Expert

Hello Experts,

I have a requirement to remove State Options from State field when it gets to certain state and add new options. I'm an on load client script, but I can't remove any options nor can I add any options. Please Help!

function onLoad() {

if(state == '40'){

  g_form.removeOption('state', '10');

  g_form.removeOption('state', '20');

  g_form.removeOption('state', '30');

  g_form.addOption('state', '50', 'Execution');

  g_form.addOption('state', '60', 'Release');

}

}

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here you go.   But what about when some one changes the state?



function onLoad() {


if(g_form.getValue('state') == '40'){


  g_form.removeOption('state', '10');


  g_form.removeOption('state', '20');


  g_form.removeOption('state', '30');



  g_form.addOption('state', '50', 'Execution');


  g_form.addOption('state', '60', 'Release');


}


}


View solution in original post

5 REPLIES 5

kente
Tera Guru

There is something about the IF statement.


I think it should be if(g_form.getValue('state') == '40'){


Thanks Kent, that was it!


Abhinay Erra
Giga Sage

Here you go.   But what about when some one changes the state?



function onLoad() {


if(g_form.getValue('state') == '40'){


  g_form.removeOption('state', '10');


  g_form.removeOption('state', '20');


  g_form.removeOption('state', '30');



  g_form.addOption('state', '50', 'Execution');


  g_form.addOption('state', '60', 'Release');


}


}


Thanks! That worked. So states are locked down and driven by the workflow until we get that point where they want to add in few states and have it be manually updated. So we're using a ui policy to make the state editable after the last step in the workflow.