Business rules for dependent variables

pavam
Tera Contributor

I am having 3 variables, all are reference fields  on a custom table.

 

Var1 is in custom table and is a reference field, and Var 1 type in table is reference to another master table.

Var2 is in custom table and is a reference field, and Var 2 type in table is reference to another master table.

Var3 is in custom table and is a reference field, and Var 3 type in table is reference to another master table.

 

var 1 is having dupilicate entries, and var2 has to populate based on var1

 

 and Var3 has to populate based on the Var2 and Var 1.

 

I have written the code like this,

 

Var 1 and Var 2 are working

 Var 3 is not working.

 

Var1 is BusinessGroup

Var2 is BusinessUnits

Var3 is world area.  (this part is not working)

 

 BusinessGroup : function(){
         
         
          gs.log(" level3 in si"+level3)
         var choices=[];
         var gr= new GlideAggregate('u_ehsvelocities');
         gr.groupBy('u_business_group');
         gr.query();
         
         while (gr.next()){
            gs.log(" level3 in si in loop"+gr.u_business_group);
            choices.push (gr.getValue('u_business_group').toString());

         }
         //return JSON.stringify(choices);
          return 'sys_idIN' +chocies;
    },


        BusinessUnits : function(BusinessGroup){
         gs.log(" level4 business Unit"+ BusinessGroup );
         
         var unitchoices=[];
         var gr= new GlideRecord('u_ehsvelocities');
         gr.addQuery('u_business_group',BusinessGroup);
         gr.query();
         
         while (gr.next()){
            gs.log(" level4 in while loop"+gr.u_business_unit);
          unitchoices.push (gr.getValue('u_business_unit').toString());
         }
         
          return 'sys_idIN' +unitchoices;
    },
     
        WorldArea : function(BusinessUnits){

         gs.log("level5 WorldArea "+ worldArea );
         
         var worldareas=[];
         var gr= new GlideRecord('u_ehsvelocities');
         gr.addQuery('u_business_group',BusinessGroup);
         gr.query();
         while (gr.next()){
            gs.log(" level5 in while loop"+gr.u_world_area);
          worldareas.push (gr.getValue('u_world_area').toString());
         }
         
          return 'sys_idIN' +worldareas;
   
   

 

3 REPLIES 3

Mark Manders
Mega Patron

I think you are not passing the businessgroup to your last one. And are you sure the first part is working, or didn't you copy/paste the code? There's a type in the return for 'choices'.

 

Can you check if this works:

// BusinessGroup function to fetch unique Business Groups
BusinessGroup : function() {
    gs.log("Fetching Business Groups");

    var choices = [];
    var gr = new GlideAggregate('u_ehsvelocities');
    gr.groupBy('u_business_group');
    gr.query();

    while (gr.next()) {
        gs.log("Business Group: " + gr.u_business_group);
        choices.push(gr.getValue('u_business_group').toString());
    }

    return 'sys_idIN' + choices.join(',');
},

// BusinessUnits function to fetch based on BusinessGroup
BusinessUnits : function(BusinessGroup) {
    gs.log("Fetching Business Units for Business Group: " + BusinessGroup);

    var unitchoices = [];
    var gr = new GlideRecord('u_ehsvelocities');
    gr.addQuery('u_business_group', BusinessGroup);
    gr.query();

    while (gr.next()) {
        gs.log("Business Unit: " + gr.u_business_unit);
        unitchoices.push(gr.getValue('u_business_unit').toString());
    }

    return 'sys_idIN' + unitchoices.join(',');
},

// WorldArea function to fetch based on both BusinessGroup and BusinessUnits
WorldArea : function(BusinessGroup, BusinessUnits) {
    gs.log("Fetching World Areas for Business Group: " + BusinessGroup + " and Business Units: " + BusinessUnits);

    var worldareas = [];
    var gr = new GlideRecord('u_ehsvelocities');
    gr.addQuery('u_business_group', BusinessGroup);
    gr.addQuery('u_business_unit', BusinessUnits);
    gr.query();

    while (gr.next()) {
        gs.log("World Area: " + gr.u_world_area);
        worldareas.push(gr.getValue('u_world_area').toString());
    }

    return 'sys_idIN' + worldareas.join(',');
}

Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

 

yes first part is working .

 

I will try the solution provided by you.

pavam
Tera Contributor

in the variable section, i have passed like this.

pavam_0-1725806715648.png

 

this is not working.

 

How to give the reference qual here?

 

thankyou for helping,