Script include return value not working.

AnandKumar1
Tera Expert

Hi All,

I am modifying a catalog in which I have

Variable 1: List collector variable name "Application" in which i am gliding "cmdb_ci_business_application". 

Variable 2: Environment which is select box having choices with, production, DEV, QA so on.. 

 

The requirement is based on the variable 1 and 2 the variable 3 should populate the value with certain condition.

 

The 3rd variable "Application server" is list collector which is to query value from custom table "u_m2m_servers_applications". The values from variable 1 and 2 to be passed to M2M table and we have to pick the related server.

For instance in the M2M table iam querying application with environment there will be some 5 values which will be matching, and will be showing in list collector of variable 3. I dont want to list down the retired / decomm.

 

The challenging is the server should not be retired or decommission. 

 

From the reference qualifier we can able to pass the value of variable 1 and 2. But we cannot put the condition for DOTWALKING the server status information. 

 

So i tried using a script include to fetch the value. But i am stuck with return value how to pass it back to variable. Please find my script below.

 

AnandKumar1_0-1698178016236.png

var ServerApplications = Class.create();
ServerApplications.prototype = {
    initialize: function() {},
 
    relatedServer: function(application, environment) {
        gs.log('AK function call');
        var serverSysId = null;
        gs.log("AK function inner test param" + application + "*" + environment, "Serverapp");
 
        var m2m = new GlideRecord('u_m2m_servers_applications');
        m2m.addQuery('u_application', application);
        m2m.addQuery('u_application.environment', environment);
        m2m.query();
        if (m2m.next()) {
            serverSysId = m2m.u_server.toString();
 
 
            var serverGr = new GlideRecord('cmdb_ci_server');
            if (serverGr.get(serverSysId) && !serverGr.retired && !serverGr.decommission) {
               // got stuck with return values.
return ; 
                gs.log("AK function true value " + serverGr, "Serverapp");
            }
            return ;
            gs.log("AK function false value " + serverGr, "Serverapp");
        }
 
    },
 
    type: 'ServerApplications'
};
 
Thanks.

 

9 REPLIES 9

Brad Bowman
Kilo Patron
Kilo Patron

A reference qualifier on a list collector (or reference) variable that calls a Script Include should return the value 'sys_idIN' + a comma-separated list of sys_ids on the referenced/list table of the desired records.  This is best done by pushing the sys_ids to an array in the Script Include, then returning the joined array after 'sys_idIN'.  So your Script Include needs to take whatever variables you pass into it and come up with a list of sys_ids to push to an array.

 

Also, since this is a List Collector type variable, be sure to use the Variable attribute like ref_qual_elements=var1,var2 naming each variable where a new value should cause the list filter to update.

Thanks for your Reply Brad. But my script on the function parameter is working 

relatedServer: function(application, environment) {

 

But the glide with m2m table is not working. Am i missing something? Since i cannot see the logs when i tried. 

Make sure the Script Include is Client callable.  Are you seeing the 'AK function call' and 'AK function inner test param' logs?  Add more logs to see where the script is not getting the correct if statements or GlideRecords.  Even if/when the SI works completely, your final statement is 'return;' which isn't going to resolve to the reference qualifier anything useful - it needs to return 'sys_idIN' + a comma-separated list of sys_ids from the list table.  

Hi Brad,

Yes, I can see first 2 logs. Now i will try with returning this through array. 

 

AnandKumar1_0-1698180643412.png

 

Hi @AnandKumar1 ,

Just checking , if your problem resolved now. Please share the issue area ( if resolved ).

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution