Workflow error : ' GlideAjax is not defined'

abhiyadav2001
Giga Expert

Hi,

 

I am calling a 'script include' in workflow. Script is marked as 'client callable'. This workflow is attached to 'Catalog item'.

 

When I create a request and check workflow, SNow is showing me an error message ; 'GlideAjax is not defined'.

 

Below is my code.. I dont know what am I missing here ?

 

// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.

//

// For example,

//

//     answer = ifScript();

//

//     function ifScript() {

//           if (condition is true) {

//                 return 'yes';

//           }

//           return 'no';

//     }

 

isManager();

 

          function isManager(){                      

                var ga = new GlideAjax('verifyIfManager'); // script include name

              ga.addParam('sysparm_name', 'checkifManager') // function name to be called

      ga.addParam('sysparm_userName', groupList); // parameter

      ga.addParam('sysparm_groupName',userGroup); // parameter

      ga.getXML(parseAnswer);     } // response

 

// response function

function parseAnswer(response) {

 

var result = response.responseXML.getElementsByTagName("result");

var message = result[0].getAttribute("message");

 

if (message) { return 'yes' ;}

else { return 'no';}

}

1 ACCEPTED SOLUTION

Hi Abhijeet,



                                  Dont pass the parameters. You can write   current.current.userName in includescript .



Wite this below code in Workflow.



Workflow


_____________


gs.include("verifyIfManager");


var verify = new verifyIfManager();


var result = verify.checkifManager();



Write this below code in includescript


_____________________________




checkifManager : function(){


var userName = current.username;


var groupName = current.group_name;



write your code according to your requirement



return answer;


}




Regards,


Harish.


View solution in original post

10 REPLIES 10

abhiyadav2001
Giga Expert

I also tried removing 'new' in Glide Ajax call.. Its throwing the same error.


AnishSasidharan
Mega Expert

function isManager(){                      


                var ga = new GlideAjax('verifyIfManager'); // script include name


              ga.addParam('sysparm_name', 'checkifManager') // function name to be called


      ga.addParam('sysparm_userName', groupList); // parameter


      ga.addParam('sysparm_groupName',userGroup); // parameter


      ga.getXML(parseAnswer);     } // response



// response function


function parseAnswer(response) {



var result = response.responseXML.getElementsByTagName("result");


var message = result[0].getAttribute("message");



if (message) { return 'yes' ;}


else { return 'no';}


}



Above function is written in script include ?



Please don't use GlideAjax in Script include, it is a client callable function in the sense you have to use this function only in Client script.



To call script include through workflow, you have to follow the below steps,



var call_script= new verifyIfManager();


call_script.isManager();



Thanks,


Anish


Hi Anish



That was really helpful.



Thanks,


Abhijeet


Harish Murikina
Tera Guru

Hi Abhijeet,



                          You can call Inclidescript in workflow in below format only.



                      gs.include("verifyIfManager");


                      var verify = new verifyIfManager();


                      var result = verify.checkifManager();



In includescript you can directly get parameters by current.groupList



Regards,


Harish.