How to user "ScriptLoader" or "ProblemModalUIHelpers" in Agent Workspace?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2020 08:35 PM
Hi all,
In UI Action, the following client script is defined, however, this script doesn't work for Agent Workspace.
How can I do the same thing for Agent Workspace?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2022 02:08 AM
Additional information on this:
The possible workaround using g_ui_scripts is described here:
If calling a UI script outside of an Angular context using IE11, call the script directly using the g_ui_scripts['nameOfScript'];
syntax.
https://developer.servicenow.com/dev.do#!/reference/api/rome/client/GUIScriptsAPI
However, this does not seem to work for Workspace in all cases. Most of the functions by ServiceNow use a GlideAjax on the Workspace script:
For example closeComplete UI Action on HR Task:
function closeComplete() {
var sysId = typeof rowSysId == 'undefined' || rowSysId == null ? g_form.getUniqueValue() : rowSysId;
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecord("sn_hr_core_task", sysId, promptDialog);
});
function promptDialog(taskGr) {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('sn_hr_core_HR Task Comment Dialog');
dialog.setTitle(getMessage('Provide a summary of the work performed'));
dialog.setPreference('sysparm_task_sys_id', sysId);
dialog.setPreference('sysparm_ok_method_name', 'closeCompleteTask');
dialog.setPreference('sysparm_is_comment', 'false');
dialog.setPreference('sysparm_task_table', 'sn_hr_core_task');
dialog.on('hrTaskComentDialogSucess', function() {
dialog.destroy();
gsftSubmit(null, g_form.getFormElement(), 'sysverb_update_and_stay');
});
dialog.render();
return;
}
}
if (typeof window == 'undefined')
serverClose();
function serverClose() {
if (current.work_end.nil())
current.work_end = new GlideDateTime().getDisplayValue();
current.state = 3;
current.update();
action.setRedirectURL(current);
}
For Workspace they use this code:
function onClick(g_form) {
getMessages(['Work Notes', 'Provide a summary of the work performed'], function(){
var sysId = typeof rowSysId == 'undefined' || rowSysId == null ? g_form.getUniqueValue() : rowSysId;
//Setup the fields for modal
var fields = [{
type: 'textarea',
name: 'work_notes',
label: getMessage('Work Notes'),
mandatory: true
}];
//Create the modal
g_modal.showFields({
title: getMessage('Provide a summary of the work performed'),
fields: fields,
size: 'md'
}).then(function(fieldValues){
//Get the new worknote
var newWorkNote = fieldValues.updatedFields[0].value;
//Call to GlideAjax to close the task
var gA = new GlideAjax("sn_hr_core.hr_CaseAjax");
gA.addParam("sysparm_name", "closeTask");
gA.addParam("sysparm_table_name", g_form.getTableName());
gA.addParam("sysparm_sys_id", g_form.getUniqueValue());
gA.addParam("sysparm_new_note", newWorkNote);
gA.getXMLAnswer(saveForm);
function saveForm(){
g_form.save();
}
});
});
}
Here you still display a Modal, but the results of that Modal will be passed to the Server via GlideAjax. That GlideAjax handles the processing of the data and then gets back to execute the g_form.save().