Call a UI Action from a Client Script to open a Change
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2012 08:15 AM
**I'm sure this has been done, before just can't find anything on the forum so I'm asking.**
I am trying to call a UI Action from a Client Script. I have a onChange Client Script running from the Incident table that if the 'confirm' value is True I'd like to automatically open a related Change record. But it's not working...thoughts?
Here's the code that I wrote that's not working.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '7' && !isLoading && g_form.getValue('rfc')=='') {
var rfc = g_form.getReference('rfc');
var answer = confirm('Was this Incident resolved by a Change? If yes press OK to create a Change Record. If No press Cancel.')
//force the Resolved by Change to Mandatory if OK
if (answer == true)
gsftSubmit(null, g_form.getFormElement('name'), 'Create Change');
else
g_form.setMandatory('rfc', false);
return;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2012 10:32 AM
You have to add it to the UI action not the client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2012 10:47 AM
So just to make sure that I'm not missing something:
Here's my Client Script and UI action
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '7' && !isLoading && g_form.getValue('rfc')=='') {
var rfc = g_form.getReference('rfc');
var answer = confirm('Was this Incident resolved by a Change? If yes press OK. If No press cancel.')
//Call Create Change UI Action is true
if (answer == true)
gsftSubmit(null, g_form.getFormElement(), 'change_request');
else
g_form.setMandatory('rfc', false);
return;
}
}
Create Change UI Action:
var change = new GlideRecord("change_request");
var ch = new GlideRecord('change');
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.requested_by = current.assigned_to;
change.assigned_to = current.assigned_to;
change.work_notes = current.work_notes;
change.justification = "This RFC is to document an emergency break/fix change that was made during an active incident investigation ir order to restore service.";
change.u_work_characterization = "Emergency Break/Fix";
var sysID = change.insert();
current.rfc = sysID;
current.state = 4;
var mySysID = current.update();
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change);
action.setReturnURL(current);
ch.insert();
action.setRedirectURL(ch);// to redirect the the user to the newly created change record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2012 11:39 AM
Try this....
//Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '7' && !isLoading && g_form.getValue('rfc')=='') {
var rfc = g_form.getReference('rfc');
var answer = confirm('Was this Incident resolved by a Change? If yes press OK. If No press cancel.')
//Call Create Change UI Action is true
if (answer == true)
gsftSubmit(null, g_form.getFormElement(), 'change_request');
else
g_form.setMandatory('rfc', false);
}
}
//Create Change UI Action:
var change = new GlideRecord("change_request");
change.short_description = current.short_description;
change.description = current.description;
change.cmdb_ci = current.cmdb_ci;
change.priority = current.priority;
change.requested_by = current.assigned_to;
change.assigned_to = current.assigned_to;
change.work_notes = current.work_notes;
change.justification = "This RFC is to document an emergency break/fix change that was made during an active incident investigation ir order to restore service.";
change.u_work_characterization = "Emergency Break/Fix";
var sysID = change.insert();
current.rfc = sysID;
current.state = 4;
current.update();
gs.addInfoMessage("Change " + change.number + " created");
action.setRedirectURL(change); // to redirect the the user to the newly created change record.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2015 07:13 AM
I think you need to initialize the change.
So after
var change = new GlideRecord("change_request");
do
change.initialize();
This will give you a clean record to add values to.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-15-2012 12:29 PM
It just goes back to the Incident Queue. :0(
