How to call script include in workflow?

kalyan778
Mega Guru

Hi All,

Can you anyone please let me know how to call script include from workflow.

Script include:

var HelloWorld = Class.create();  

HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {  

  helloWorld: function() {  

  var arr1 =   this.getParameter('sysparm_user_name') ;

  var values = '';  

  var array = arr1.split(',');  

  for(i=0;i<array.length;i++)  

  {  

  var the_choice = new GlideRecord('sys_user_grmember');  

  the_choice.addQuery('sys_id', array[i]);

  the_choice.query();  

  if(the_choice.next()){  

  values = the_choice.user.user_name.getDisplayValue() + "," + values;  

 

 

  }  

  }  

  return values;  

 

  },

Thanks in advace

1 ACCEPTED SOLUTION

kalyan778
Mega Guru

We used a separate function in the same SI , it resolves that issue.

View solution in original post

8 REPLIES 8

srinivasthelu
Tera Guru

Hi Kalyan,



Check out the worklfow, add a new run script activity and call something like this.



new ScriptIncludeName().functionName();



In the above scenario, the HelloWorld function cannot be callable from script include as it is written to accept parameters through AJAX.



You can modify the above script something like below,




var HelloWorld = Class.create();


HelloWorld.prototype = Object.extendsObject(AbstractAjaxProcessor, {


  helloWorldAjax: function() {


var arr=this.getParameter('sysparm_user_name') ;


this.helloWorld(arr);


},


helloWorld: function(arr1) {


  var values = '';


  var array = arr1.split(',');


  for(i=0;i<array.length;i++)


  {


  var the_choice = new GlideRecord('sys_user_grmember');


  the_choice.addQuery('sys_id', array[i]);


  the_choice.query();


  if(the_choice.next()){


  values = the_choice.user.user_name.getDisplayValue() + "," + values;



}


  }


return values;


  }


 


  }


Hi Srinivas,


Thanks for the help.



In client script I have called with below script:


var a =g_form.getValue('UsersRemoved').split(',');  


      //alert(a);  


      var ga = new GlideAjax('HelloWorld');  


      ga.addParam('sysparm_name','helloWorld');  


      ga.addParam('sysparm_user_name',a);  


      ga.getXML(HelloWorldParse);  


         


      function HelloWorldParse(response) {  


            var answer = response.responseXML.documentElement.getAttribute("answer");  


            //alert(answer);  


       



      }  



But now in workflow as well I need to get the field and run with Scriptinclude .



Can you suggest.



Thanks


Hi Kalyan,



You can call the script include form the workflow as


new ScriptIncludeName().functionName();



Please let me know if you have any questions.


Basically you can fetch the field value on the workflow as


current.short; //Replace short with the exact field column name


For service catalog items you have to fetch the field value on the workflow as


current.variables.short; //Replace short with the exact name of the variable you have created.