Set a default value to a list choice through UI Action

r_daosseili
Kilo Contributor

Hello,

I added a new choice option for the incident's state which is "Awaiting Change" as shown below:

Capture d

Capture d

What I want to do is to set the state to "Awaiting Change" when a Change is created from the incident using "Create Normal Change" or "Create Emergency Change" UI action.

For that I went to UI Action -> Create Normal Change (where table is INCIDENT).

I tried to change the value through the script but it doesn't seem to work. I wonder if this doable only via scripting or if there is an other way to do that.

Capture d

Thank you for your the help.

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

What you've done there is attempt to set the CHANGE REQUEST's state.  
You'll notice that after the changeRequest.insert() the OOB UI Action also does some updates to the current record (the incident you launched the change from).   Just do you state update there (but before current.update()).



(function(current, previous, gs, action) {


      var changeRequest = ChangeRequest.newNormal();


      changeRequest.setValue("short_description", current.short_description);


      changeRequest.setValue("description", current.description);


      changeRequest.setValue("cmdb_ci", current.cmdb_ci);


      changeRequest.setValue("priority", current.priority);


      changeRequest.setValue("sys_domain", current.sys_domain);


      changeRequest.setValue("company", current.company);


      changeRequest.insert();


   


        //this is where you're going to handle incident updates


      current.state = <whatever the state value is>


      current.rfc = changeRequest.getGlideRecord().getUniqueValue();


      current.update();


   


      gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");


      action.setRedirectURL(changeRequest.getGlideRecord());


      action.setReturnURL(current);


   


})(current, previous, gs, action);


View solution in original post

3 REPLIES 3

Uncle Rob
Kilo Patron

What you've done there is attempt to set the CHANGE REQUEST's state.  
You'll notice that after the changeRequest.insert() the OOB UI Action also does some updates to the current record (the incident you launched the change from).   Just do you state update there (but before current.update()).



(function(current, previous, gs, action) {


      var changeRequest = ChangeRequest.newNormal();


      changeRequest.setValue("short_description", current.short_description);


      changeRequest.setValue("description", current.description);


      changeRequest.setValue("cmdb_ci", current.cmdb_ci);


      changeRequest.setValue("priority", current.priority);


      changeRequest.setValue("sys_domain", current.sys_domain);


      changeRequest.setValue("company", current.company);


      changeRequest.insert();


   


        //this is where you're going to handle incident updates


      current.state = <whatever the state value is>


      current.rfc = changeRequest.getGlideRecord().getUniqueValue();


      current.update();


   


      gs.addInfoMessage("Change " + changeRequest.getValue("number") + " created");


      action.setRedirectURL(changeRequest.getGlideRecord());


      action.setReturnURL(current);


   


})(current, previous, gs, action);


Thank you for your answer Robert


Oh, my bad. I misunderstood the statement.


Is there another way to do it without scripting ?


What are the best practices in this case to assign the value of the state knowing that we can have different languages since the value won't be the same in different language ? Sort of binding the value to a state with the language parameter; Something like:




  1.       current.state =   getState('name_of_the_state','eng');  
  2.       current.rfc = changeRequest.getGlideRecord().getUniqueValue();  
  3.       current.update();

Hi Reda,



The following may be helpful if you want to configure a default value for a choice list:


http://wiki.servicenow.com/index.php?title=Customizing_Choice_Lists#gsc.tab=0



If you want the script to be dynamically assigned given a condition then you're going to need to use scripting somehow. The following link may help on some options to set default values of a field given a condition: Specify a default field value



I hope this helps.



Thanks,


Berny