Call client callable script include from Business Rule /Background Script

Abc 26
Tera Expert

Hello Experts,

I want to use the client callable script include from business rule /Background script. Please help.

Sample Client callable script Include script

getCallerLang: function(){
    var caller_id = this.getParameter('sysparm_caller_id');
}

Please help to fetch the output through background script.

Note : function does not have any parameter in Client callable script Include script.

@Ankur Bawiskar 

Regards
 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

yes that's possible

Same function can be called from ajax or server side like this

getCallerLang: function(caller){

	var caller_id = JSUtil.nil(caller) ? this.getParameter('sysparm_caller_id') : caller;

}

regards
Ankur

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

View solution in original post

6 REPLIES 6

@Abc 26 

Hope you are doing good.

Did my reply answer your question?

If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.

Regards
Ankur

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

Muhammad Khan
Mega Sage
Mega Sage

Hi @Abc 26 

 

Client Callable Script Include

var Test = Class.create();
Test.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	bothClientServer: function(prbSysID){
		var prb_sys_id = (prbSysID == undefined) ? this.getParameter('sysparm_prbSysID') : prbSysID;
		var prb = new GlideRecord('problem');
                prb.get(prb_sys_id);
		return prb.getValue('number');
	},

    type: 'Test'
});

Client Script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

	var ga = new GlideAjax('Test');
	ga.addParam('sysparm_name', 'bothClientServer');
	ga.addParam('sysparm_prbSysID', g_form.getValue('problem_id'));
	ga.getXML(result);

	function result(response){
		var answer = response.responseXML.documentElement.getAttribute('answer');
		alert(answer);
	}

}

Server-Side/Background Script

var obj = new Test();
gs.print(obj.bothClientServer('<sys_id_of_problem_record>'));

 

Hopefully, this will help you understand.