How to call a client-callable script-include function (accepting parameters) from server-side as well?

Pranshu3
Tera Expert

Hi all,

I have a client-callable script include in my instance. A function within this script accepts client parameters [this.getParameter('sysparm_sys_id')].

Now to reduce code redundancy, I would like to call the same function from server-side (business rule).

How to make this client-callable script-include function accept parameters and get utilized from server-side as well?

1 ACCEPTED SOLUTION

Pranshu3
Tera Expert

Hi, found the solution!

There is a one-line script to make a client-callable script-include function server-side accepted.

Add server type parameters to the function of script include:

    getIncidents: function(problemId){

Now within the function use the below code line:

    var probSysId = JSUtil.nil(problemId) ? this.getParameter('sysparm_sys_id') : problemId;

This way the function can accept parameters and can be called from both client & server side.

Thanks!

View solution in original post

7 REPLIES 7

AbhishekGardade
Giga Sage

you can call script include from business rule like below:

var ga = new ScriptIncludeName.functionName(current.caller_id,current.assignment_group);  // pass parameters you want to pass

OR

var ga= new ScriptIncludeName();

ga.functionName(current.caller_id,current.assignment_group);

Please mark as Correct Answer and Helpful, if applicable.
Thanks!
Abhishek Gardade
Hexaware Technologies

 

Thank you,
Abhishek Gardade

Pranshu3
Tera Expert

Hi, found the solution!

There is a one-line script to make a client-callable script-include function server-side accepted.

Add server type parameters to the function of script include:

    getIncidents: function(problemId){

Now within the function use the below code line:

    var probSysId = JSUtil.nil(problemId) ? this.getParameter('sysparm_sys_id') : problemId;

This way the function can accept parameters and can be called from both client & server side.

Thanks!

Thanks, this has help me a lot. Will allow me to re-use scripts.

 

however, I had to do this instead, because JSUtil is not available for my Script include.

var probSysId = "";
if (typeof problemId !== 'undefined') {
	probSysId = problemId ;
} else {
	probSysId = this.getParameter("sysparm_sys_id");
}

Hi Benoit,

I'm also having the same requirement.

Could you please let me understand above code?

I'm not able to get it.

 

Thanks,

Ankita