UI action in wokspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
I want to show a pop-up if there are related tasks before closing the parent case.
The below code is working for native UI but how to add the same functionality in workspace? Need the same feature of "global.StateFlow().processFlow" in workspace as well.
function runClientCode() {
if (!g_form.getValue("assigned_to")) {
g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assign To field before moving the request to Awaiting Info or Resolved.');
return false;
}
var gaCheck = new GlideAjax("sn_customerservice.CheckTaskRecord");
gaCheck.addParam('sysparm_name', 'checkIfTask');
gaCheck.addParam('sysparm_request_id', g_form.getUniqueValue());
gaCheck.getXMLAnswer(function(response) {
if (response == "1") {
if (confirm("Resolution of request will close all open tasks. Do you want to proceed?")) {
var gaResolve = new GlideAjax("sn_customerservice.CheckTaskRecord");
gaResolve.addParam('sysparm_name', 'closeTaskRecord');
gaResolve.addParam('sysparm_request_id', g_form.getUniqueValue());
gaResolve.getXMLAnswer(function(answer) {
if (answer == "1") {
g_form.addInfoMessage("test4");
gsftSubmit(null, g_form.getFormElement(), 'proposeSolution');
}
});
} else
return false;
} else
gsftSubmit(null, g_form.getFormElement(), 'proposeSolution');
});
}
if (typeof window == 'undefined') {
runServerCode();
}
function runServerCode() {
new global.StateFlow().processFlow(current, 'sys_id', 'manual');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Ensure these 2 checkboxes are selected and add script in workspace client script
You can check OOTB UI actions and add the code accordingly
Something like this in workspace client script
function onClick(g_form) {
if (!g_form.getValue("assigned_to")) {
g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assign To field before moving the request to Awaiting Info or Resolved.');
return false;
}
var gaCheck = new GlideAjax("sn_customerservice.CheckTaskRecord");
gaCheck.addParam('sysparm_name', 'checkIfTask');
gaCheck.addParam('sysparm_request_id', g_form.getUniqueValue());
gaCheck.getXMLAnswer(function(response) {
if (response == "1") {
if (confirm("Resolution of request will close all open tasks. Do you want to proceed?")) {
var gaResolve = new GlideAjax("sn_customerservice.CheckTaskRecord");
gaResolve.addParam('sysparm_name', 'closeTaskRecord');
gaResolve.addParam('sysparm_request_id', g_form.getUniqueValue());
gaResolve.getXMLAnswer(function(answer) {
if (answer == "1") {
g_form.addInfoMessage("test4");
g_form.submit('proposeSolution');
}
});
} else
return false;
} else
g_form.submit('proposeSolution');
});
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
the script include is not calling from workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @Rosy14
Sample Script Include: GlideAjax / Client Callable checked
var CheckTaskRecord = Class.create();
CheckTaskRecord.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
checkIfTask: function() {
var incidentId = this.getParameter('sysparmRequestId');
var childGr = new GlideRecord('incident');
childGr.addQuery('parent_incident', incidentId);
childGr.addActiveQuery();
childGr.query();
if (childGr.hasNext()) {
return "1";
} else {
return "0";
}
},
processStateFlow: function() {
var incidentId = this.getParameter('sysparmRequestId');
var incidentGr = new GlideRecord('incident');
if (incidentGr.get(incidentId)) {
new global.StateFlow().processFlow(incidentGr, incidentId, 'manual');
return "1";
}
return "0";
},
type: 'CheckTaskRecord'
});
UI Action - Client checked (list v2 + list v3 compatible checked)
Script:
function runClientCode() {
if (!g_form.getValue("assigned_to")) {
g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assigned To field before resolving the incident.');
return false;
}
var incidentSysId = g_form.getUniqueValue();
var gaResolve = new GlideAjax("CheckTaskRecord");
gaResolve.addParam('sysparm_name', 'checkIfTask');
gaResolve.addParam('sysparmRequestId', incidentSysId);
gaResolve.getXMLAnswer(function(answer) {
if (answer == "1") {
alert('Resolution of the incident will close all open tasks. Do you want to proceed?');
return false;
} else {
gsftSubmit(null, g_form.getFormElement(), 'resolveIncident');
}
});
}
if (typeof window == 'undefined') {
runServerCode();
}
function runServerCode() {
new global.StateFlow().processFlow(current, current.sys_id, 'manual');
}
Workspace Form Button Checked
Workspace Client Script
function onClick(g_form) {
if (!g_form.getValue("assigned_to")) {
g_form.addErrorMessage('Assigned To cannot be empty. Please fill the Assigned To field before resolving the incident.');
return false;
}
var incidentSysId = g_form.getUniqueValue();
var gaResolve = new GlideAjax("CheckTaskRecord");
gaResolve.addParam('sysparm_name', 'checkIfTask');
gaResolve.addParam('sysparmRequestId', incidentSysId);
gaResolve.getXMLAnswer(function(answer) {
if (answer == "1") {
g_modal.alert('Resolution of the incident will close all open tasks. Do you want to proceed?');
return false;
} else {
triggerServerFlow(g_form, incidentSysId);
}
});
}
function triggerServerFlow(g_form, incidentSysId) {
var flowAjax = new GlideAjax("CheckTaskRecord");
flowAjax.addParam('sysparm_name', 'processStateFlow');
flowAjax.addParam('sysparmRequestId', incidentSysId);
flowAjax.getXMLAnswer(function(flowResponse) {
if (flowResponse == "1") {
g_form.addInfoMessage("Incident resolved successfully.");
if (g_form.refresh)
g_form.refresh();
} else {
g_form.addErrorMessage("Unable to resolve the incident.");
}
});
}
Validation Results
Workspace:
Native UI
Hope that helps!
