Calling script include answer

josh_brostoff
Giga Contributor

I have a script I want to execute depending on if the answer for a script include returns true or false.   I invoke the script include at the beginning of my script and want to add if "if/else" statement to decide wether or not the script should execute.   How can I do this?

(Script I want to execute if script include returns true)

Screen Shot 2017-01-23 at 5.52.44 PM.png

(Script include)

Screen Shot 2017-01-23 at 5.52.31 PM.png

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Josh,



var slack = new SlackUser();


var res = slack.activeUser(); //This would return true or false depeding on the output from Script include.



Please let me know if you have any questions.


View solution in original post

5 REPLIES 5

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Josh,



var slack = new SlackUser();


var res = slack.activeUser(); //This would return true or false depeding on the output from Script include.



Please let me know if you have any questions.


Hi Pradeep - I tried this, but no luck:



var slack = new SlackUser();


var res = slack.activeUser()




if (res = false)


  {


  answer += 'Test'


  }




else {


//do this


}


kristenankeny
Tera Guru

when calling the script include, you want to include which function to call:



var slack = new GlideAjax('SlackUser');


slack.addParam('sysparm_name','activeUser');


slack.getXML(callback);



Then, in that same script, you want to add a callback function:


function callback(response){


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


if(ans == true){


//what you want to do


}


else{


//what you want to do


}


If I use onSubmit client script

and if Script include returns false, then Form should not submit. 

what should I use for this? and where?