How to Script an 'alert' from a UI Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2012 12:36 PM
When I click the 'Close Task' button on an sc_task form, I want to be able to check the corresponding RITM form to ensure some custom fields are populated before I allow the task to close. If the fields are not populated, I'd like to have an 'alert' tell the analyst about the error. I've build a UI action on the 'Close Task' button (screenshot attached), but I can't quite get it to work. The script I've written looks like this...
~~~~~~~~~~~~~~~~~~~~~
var ritm = new GlideRecord('sc_req_item');
ritm.get(current.request_item.sys_id);
If (ritm.u_access_application.nil() || ritm.u_access_server.nil() || ritm.u_access_website.nil()){
alert('Mandatory fields on the RITM form are not populated, you cannot proceed until they are.');
current.setAbortAction(true);
}
current.state = 3;
current.update;
~~~~~~~~~~~~~~~~~~~~~
Has anyone done alerts from a UI action before? Checked fields on the RITM form from the task form through a UI Action? See anything wrong with my code?
Any help would be very much appreciated!
With thanks... Karen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2012 12:19 PM
Thanks everyone, I got it working. It didn't like the .nil() function either. Here's what eneded up working...
function check() {
var ritm = new GlideRecord('sc_req_item');
ritm.get(g_form.getValue('request_item'));
if(ritm.u_access_application=="") {
alert("Mandatory fields on the RITM form are not populated, you cannot proceed until they are and your changes saved");
current.setAbortAction(true);
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'close_task'); //MUST call the 'Action name' set in this UI Action
}
current.state = 3;
current.update();