How to call a script include from within a Run Script Workflow Activity?

patricklatella
Mega Sage

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;
}
}
}
};

 

 

1 ACCEPTED SOLUTION

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.

View solution in original post

7 REPLIES 7

Zeeshan Khan1
Kilo Guru

Hi,

 

Since this script include is not client callable, you can directly get the parameters from the function call itself without needing "this.getParameter(paramName)" statement.

 

So, you can try changing your GetUserADGroup function as below (changes marked as bold) :

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;
}
}
}

 

ok great, thanks Zeeshan, trying that now.  Is my script within the Run Script activity correct?  How do I receive the value back from the script include?

Your script withing Run script activity looks fine, but just noticed that you are not returning any value from your GetUserADGroup function. You may want to add a return statement at the end passing back 'retVal'.

ok...what should the return statement look like?