- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 07:04 AM
Hello
I am trying to create a background script for closing a change, for which workflow has broken. Advise on it please.
function getUserRegion() {
var u = gs.getnumber();
var gr = new GlideRecord('change_request');
gr.addQuery('CHG00046',u);
gr.query();
while (gr.next()) {
gr.u_stage= 7;
gr.update();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 05:18 AM
If you need to change the state, then update the script to use the state field instead.
var gr = new GlideRecord('change_request');
if (gr.get('number', 'CHG00046')) {
gr.state= 7;
gr.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 07:30 AM
If you are just running it from scripts background, you can either a) leave off the function wrapper, b) change it to an anonymous function.
var gr = new GlideRecord('change_request');
if (gr.get('number', 'CHG00046')) {
gr.u_stage= 7;
gr.update();
By using the new GlideRecord('change_request') you are telling it you are about to interact with the change_request table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2017 07:32 AM
Yeah, it appears to be correct, so long as your Change Request numbers are only five digits. Otherwise it would be 'CHG0000046'.
Since you expect one and only one result, while (gr.next()) could simply be if (gr.next()). Chuck's code is plug-and-play, so you can copy his if you want to be sure.
(ctomasi beat me to it again.. )
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 01:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 04:31 AM
gr.state=3 should update the state to closed.
You should review the sys_choice table, element - 'state', table change_request to verify that state=3 corresponds to 'Closed'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2017 09:14 AM
Thanks for the clear update Chris
