- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2018 05:06 PM
Hi Community,
I'm trying to call a script include from within a Run Script workflow activity to return a value from a GlideRecord query. Having a little trouble...I think I'm close...any help would be great...thanks!
What does the script in the workflow activity need to be to call the script include, pass 2 values, and the then get the answer back?
right now my script looks like this...not sure how to reference what the script include is sending back?
var application = workflow.scratchpad.application; //first value to pass
var userDomain = workflow.scratchpad.user_domain; //second value to pass
var obj = new u_ActiveDirectoryGroup_lookup(); //name of script include
var arr = obj.GetUserADGroup(userDomain, application); //name of function with the 2 value parameters
and here's my script include...again not sure this is correct...from my log entries I'm not sure it's receiving the passed values correctly.
var u_ActiveDirectoryGroup_lookup = Class.create();
u_ActiveDirectoryGroup_lookup.prototype = {
initialize: function() {
},
GetUserADGroup: function(){
var retVal;
var adDomain = this.getParameter('sysparm_adDomain');
var application = this.getParameter('sysparm_application');
var gr = new GlideRecord('u_ad_group_lookup');
gr.addQuery('u_user_ad_domain',adDomain);
gr.addQuery('u_application',application);
gr.query();
if(gr.next()){
if(gs.getProperty('glide.orchestration.redirect.enabled') == 'true'){
retVal = gs.getProperty('glide.orchestration.redirect.group');
gs.info("Orchestration redirect is enabled, if it wasn't then the AD group for user would be "+gr.u_ad_group+". This log is from the u_ActiveDirectoryGroup_lookup script include.");
}else{
retVal = gr.u_ad_group;
}
}
}
};
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2018 05:26 PM
Added below in bold:
var u_ActiveDirectoryGroup_lookup = Class.create();
u_ActiveDirectoryGroup_lookup.prototype = {
initialize: function() {
},
GetUserADGroup: function(adDomain, application){
var retVal;
//var adDomain = this.getParameter('sysparm_adDomain');
//var application = this.getParameter('sysparm_application');
var gr = new GlideRecord('u_ad_group_lookup');
gr.addQuery('u_user_ad_domain',adDomain);
gr.addQuery('u_application',application);
gr.query();
if(gr.next()){
if(gs.getProperty('glide.orchestration.redirect.enabled') == 'true'){
retVal = gs.getProperty('glide.orchestration.redirect.group');
gs.info("Orchestration redirect is enabled, if it wasn't then the AD group for user would be "+gr.u_ad_group+". This log is from the u_ActiveDirectoryGroup_lookup script include.");
}else{
retVal = gr.u_ad_group;
}
}
return retVal;
}
};
Note : As per your code, retVal will be null if there is no record with the above query in u_ad_group_lookup table. I think this condition "if(gs.getProperty('glide.orchestration.redirect.enabled') == 'true'){" should be outside your gilde record if statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2018 05:26 PM
Added below in bold:
var u_ActiveDirectoryGroup_lookup = Class.create();
u_ActiveDirectoryGroup_lookup.prototype = {
initialize: function() {
},
GetUserADGroup: function(adDomain, application){
var retVal;
//var adDomain = this.getParameter('sysparm_adDomain');
//var application = this.getParameter('sysparm_application');
var gr = new GlideRecord('u_ad_group_lookup');
gr.addQuery('u_user_ad_domain',adDomain);
gr.addQuery('u_application',application);
gr.query();
if(gr.next()){
if(gs.getProperty('glide.orchestration.redirect.enabled') == 'true'){
retVal = gs.getProperty('glide.orchestration.redirect.group');
gs.info("Orchestration redirect is enabled, if it wasn't then the AD group for user would be "+gr.u_ad_group+". This log is from the u_ActiveDirectoryGroup_lookup script include.");
}else{
retVal = gr.u_ad_group;
}
}
return retVal;
}
};
Note : As per your code, retVal will be null if there is no record with the above query in u_ad_group_lookup table. I think this condition "if(gs.getProperty('glide.orchestration.redirect.enabled') == 'true'){" should be outside your gilde record if statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2018 05:28 PM
yep...forgot that...perfect...it's working...thanks Zeeshan!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2022 05:07 PM
Just as a side note, it seems that the only place you can call script includes on a workflow are the Script activities.
The same code just does not run calling it from the code area on an approval activity for example.
The solution was to load the script include on a Script activity and dump the values on the scratchpad and then call these from whenever you need.