Using a script include in the client controller of a SP widget

Bushra Syed
Tera Contributor

Is it possible to use a  script include in the client controller of a SP widget? If so, can I see an example?

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Bushra,

If you want to execute a script include, do it in the server side and then exchange the result with the client controller. That should be the way to do it.

In the client controller, set the variable "input" and use the server.get:

var input = {};
input.action = "your_action";

c.server.get(input).then(function(ans){
   c.data.msg = ans.data.msg;
}


Then, in the server script, you need to have something like this:

if(input && input.action=="your_Action"){
 var x = new your_script_include().your_method();
 data.msg = x;		
}

with this, you pass the result of your script include execution to data.msg and consume that in the client controller.

Hope this helps!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

3 REPLIES 3

Filipe Cruz
Kilo Sage
Kilo Sage

Hello Bushra,

If you want to execute a script include, do it in the server side and then exchange the result with the client controller. That should be the way to do it.

In the client controller, set the variable "input" and use the server.get:

var input = {};
input.action = "your_action";

c.server.get(input).then(function(ans){
   c.data.msg = ans.data.msg;
}


Then, in the server script, you need to have something like this:

if(input && input.action=="your_Action"){
 var x = new your_script_include().your_method();
 data.msg = x;		
}

with this, you pass the result of your script include execution to data.msg and consume that in the client controller.

Hope this helps!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

Hi, How do I send in parameters to the script include in the server side?

Hi Bushra,

You need to do like this: (picking the example I have before)

var input = {};
input.action = "your_action";
input.result = "input string for your script";

c.server.get(input).then(function(ans){
   c.data.msg = ans.data.msg;
}

And then in the server side:

if(input && input.action=="your_Action"){
 var x = new your_script_include().your_method(input.result);
 data.msg = x;		
}

 

Hope this helps!

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz