Server Script on UI action Workspace Client Script is not working

Nandini DM
Tera Contributor

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.

 

1 ACCEPTED SOLUTION

@Nandini DM 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

15 REPLIES 15

Ankur Bawiskar
Tera Patron
Tera Patron

@Nandini DM 

I believe your script include is not client callable

Did you check script include is getting called or not?

Also both UI action and script include are in same scope?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

 

My script include is client callable.

No, Actually I added gs.info() in my script include and got to know is not even calling script include.
And both are in same scope.

Please help.

@Nandini DM 

share the script include configuration screenshot

Also share UI action workspace client script screenshot for configuration

You should have workspace form button checkbox checked and then write that script there

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Nandini DM
Tera Contributor

@Ankur Bawiskar 

Please find the attached screenshot for reference.



@Nandini DM 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader