- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 04:46 AM
Hello All.
I am novice when comes to scripting, hence seeking help here.
I have an requirement i.e. when we change the state of a HR Task manually i need it to throw a popup where we can enter a worknote. In the Present setup there is a UI Action button created 'Close Complete' which brings up the attached dialog box, i would like the same box to popup when the state is changed manually. can anyone please help.
Solved! Go to Solution.
- Labels:
-
Case and Knowledge Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 11:02 PM
I gave it a start, built below client script, it displays the message but it is closing the task as well since the attributes to glide dialog window is taking a method which does the task closure.
PFA xml export of the client script that I created, it has couple of issues, like it is displaying a message before saying the data to worknotes and it is closing the task ( I will attempt to fix it later in the day) but thought of sharing this so that i can be a start point for your work.
The attachment is a xml export of the client script, so it needs to be imported to https://<instanceName>/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client
using the import xml option
details of the client script incase you want to create it manually.
Script =
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var sysId = g_form.getUniqueValue();
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecord("sn_hr_core_task", sysId, promptDialog);
});
}
function promptDialog(taskGr) {
var sysId = g_form.getUniqueValue();
var taskActive = taskGr.active == 'true' || taskGr.active == '1';
if (taskActive) {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('sn_hr_core_HR 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.render();
} else {
var checkAttachment = function(attachmentGr) {
if (!attachmentGr || attachmentGr.length == 0) {
if (taskActive) {
g_form.addInfoMessage(getMessage('Attachment required.'));
return false;
} else
g_navigation.reloadWindow();
} else
gsftSubmit(null, g_form.getFormElement(), gel('closeComplete').value);
};
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecordSet("sys_attachment", "table_name=sn_hr_core_task^table_sys_id=" + sysId, checkAttachment);
});
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 04:54 AM
Below link should be helpful.
https://www.servicenowguru.com/system-ui/glidedialogwindow-advanced-popups-ui-pages/
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2018 11:02 PM
I gave it a start, built below client script, it displays the message but it is closing the task as well since the attributes to glide dialog window is taking a method which does the task closure.
PFA xml export of the client script that I created, it has couple of issues, like it is displaying a message before saying the data to worknotes and it is closing the task ( I will attempt to fix it later in the day) but thought of sharing this so that i can be a start point for your work.
The attachment is a xml export of the client script, so it needs to be imported to https://<instanceName>/sys_script_client_list.do?sysparm_query=sys_class_name%3Dsys_script_client
using the import xml option
details of the client script incase you want to create it manually.
Script =
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var sysId = g_form.getUniqueValue();
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecord("sn_hr_core_task", sysId, promptDialog);
});
}
function promptDialog(taskGr) {
var sysId = g_form.getUniqueValue();
var taskActive = taskGr.active == 'true' || taskGr.active == '1';
if (taskActive) {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('sn_hr_core_HR 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.render();
} else {
var checkAttachment = function(attachmentGr) {
if (!attachmentGr || attachmentGr.length == 0) {
if (taskActive) {
g_form.addInfoMessage(getMessage('Attachment required.'));
return false;
} else
g_navigation.reloadWindow();
} else
gsftSubmit(null, g_form.getFormElement(), gel('closeComplete').value);
};
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecordSet("sys_attachment", "table_name=sn_hr_core_task^table_sys_id=" + sysId, checkAttachment);
});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 03:44 AM
Awsome!! Your script works except great just that it was popping up on all the states available. Did a little bit of RnD and added a line from another script and works just the way i want. Line "if(newValue == 20 || newValue == 3)"
Not sure if i added in the correct order, but this works for now 🙂 Thank You
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var sysId = g_form.getUniqueValue();
if(newValue == 20 || newValue == 3) //State Awaiting Acceptance or Close Complete
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecord("sn_hr_core_task", sysId, promptDialog);
});
}
function promptDialog(taskGr) {
var sysId = g_form.getUniqueValue();
var taskActive = taskGr.active == 'true' || taskGr.active == '1';
if (taskActive) {
var dialogClass = GlideModal ? GlideModal : GlideDialogWindow;
var dialog = new dialogClass('sn_hr_core_HR 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.render();
} else {
var checkAttachment = function(attachmentGr) {
if (!attachmentGr || attachmentGr.length == 0) {
if (taskActive) {
g_form.addInfoMessage(getMessage('Attachment required.'));
return false;
} else
g_navigation.reloadWindow();
} else
gsftSubmit(null, g_form.getFormElement(), gel('closeComplete').value);
};
ScriptLoader.getScripts('sn_hr_core.utils_ui.jsdbx', function() {
getGlideRecordSet("sys_attachment", "table_name=sn_hr_core_task^table_sys_id=" + sysId, checkAttachment);
});
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2018 12:29 PM
Hi Anil,
I have requirement when state value changes in hr case to closed ,I need to check any child cases are active related to that cases then any child case opened I need to populate dialog window with ok/cancel button.If they click ok I need to update parent case to closed complete ,if user click no I don't need to update parent case.Can you help me with this?