- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2023 09:20 AM
Hi,
I am trying to add server side script inside "workspace client script" whenever user clicks on the UI button on the workspace, Popup should appear Clicking on "Yes" all the related task should close based on the confirmation.
I have checked on Client callable and Format for Configurable Workspace to true.
and it is scoped application.
Below is my script, Please help me to get this working.
Workspace client script:
function onClick(g_form) {
var taskId = g_form.getUniqueValue();
var msg = getMessage("Are you sure you want to take this action?");
g_modal.confirm(getMessage("Confirmation"), msg, function(confirmed) {
if (confirmed) {
var a = new GlideAjax('sn_audit.calltask');
a.addParam('sysparm_name', "StateOfRisk");
a.addParam('sysparm_id', taskId);
}
a.getXML(copyParse);
function copyParse(response)
{
var resultMessage = response.responseXML.documentElement.getAttribute("answer");
}});
Script Include:
var calltask = Class.create();
calltask.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
StateOfRisk: function() {
var sys_id = this.getParameter('sysparm_id');
var gr = new GlideRecord("sn_audit_task");
gr.addQuery('parent',sys_id);
gr.query();
while(gr.next()){
gr.state = 7;
gr.update();
}
},
type: 'calltask'
});
It's not calling the script include , I checked by adding the logs. Please help me to know where I'm going wrong.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2023 07:31 AM
try this
function onClick(g_form) {
var msg = getMessage("Are you sure you want to take this action?");
g_modal.confirm(getMessage("Confirmation"), msg).then(function onSuccess() {
var taskId = g_form.getUniqueValue();
var a = new GlideAjax('sn_audit.calltask');
a.addParam('sysparm_name', "StateOfRisk");
a.addParam('sysparm_id', taskId);
a.getXMLAnswer(copyParse);
});
function copyParse(response)
{
// do nothing
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā06-30-2023 11:27 AM
Hi Nanadini,
I don't see any gs.info() message in the script include, to see if that is being called. You can't use 'gs.log();' in scoped applications. Add "gs.info('calltask: Using " + sys_id + " to find parents in sn_audit_task, Found " + gr.getRowcount() + " records to process."); just before the 'while' statement. Then you can check Script Log Statements module to find your log message.
Also 'sys_id' as a variable name may not work, and there are problems using "gr" as a GlideRecord variable. See:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0713029
Anyway, add the gs.info() line to code and see what you get in the log.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2023 01:34 AM
Hi Bert,
I tried adding gs.info() before while as you mentioned and also I tried to change sys_id to some other name, But still it is not getting inside the script include.
Script Include:
var calltask = Class.create();
calltask.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
StateOf: function() {
var parent = this.getParameter('sysparm_id');
var task = new GlideRecord("sn_audit_task");
task.addQuery('parent', parent);
task.query();
gs.info('03/07');
while (task.next()) {
task.state = 7;
task.update();
}
return true;
},
type: 'calltask'
});
Still not working please look into this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2023 06:18 AM
Hi @Nandini DM
Try:
var taskID = this.getParameter("sysparm_id");
task.addQuery('parent', taskID);
before 'task.query();'
The use "gs.info("Found " + taskGetRowCount() + " records to process.");
after the query. See what you get in Script Log Statements.
My example Client Script logic follows:
function onLoad() {
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('HelloWorld'); // HelloWorld is the script include name
ga.addParam('sysparm_name','responseStr'); // is the function in the script include that we're calling
// ga.addParam('sysparm_user_name','fred.luddy'); // set user to Fred Luddy
ga.addParam('sysparm_user_name',g_user.userName); // get current user
/* Call HelloWorld.responseStr() with user set to Fred Luddy and use the callback function ManagerParse() to return the result when ready */
ga.getXMLAnswer(ManagerParse);
}
// callback function for returning the result from the script include
function ManagerParse(response) {
alert(response);
}
And make sure both the Client Script and Script include are in the same application scope.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā07-03-2023 07:01 AM
@Bert_c1
I tried onLoad() client script, It is calling script include and working as expected, But the problem is "workspace client script" is not calling script include and both are in the same scope.