- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 02:17 PM
Hello,
I added a new choice option for the incident's state which is "Awaiting Change" as shown below:
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.
Thank you for your the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 02:43 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 02:43 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 03:51 PM
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:
- current.state = getState('name_of_the_state','eng');
- current.rfc = changeRequest.getGlideRecord().getUniqueValue();
- current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2016 04:36 PM
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