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

Nandini DM
Tera Contributor

@Ankur Bawiskar 

I tried with the provided solution but still not calling script include.

Nandini DM
Tera Contributor

@Ankur Bawiskar 

Till function call info message is getting displayed , facing issue after function call which is not getting inside the function.

@Nandini DM 

so are you saying you are not getting info message within the callback method?

but is it updating the record as per script include function? If yes then you need not worry

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

@Ankur Bawiskar 

No, it is not updating the form
I do not see any logs on script Include
It is not call my script include

@Nandini DM 

don't add gs.log() as it won't work in scoped app

use gs.info()

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