Returning one records when calling script include on reference quailfier

Aarushi1991
Tera Contributor

Hello Folks,

i have Incident table  i have create fields u_business_unit reference to business_unit table and u_deep which is reference to customer table 

 

in customer table i have create 3 fields one is department (refe to cmn_department) and BU (ref to business_unit)

thats how its look like now

 

Aarushi1991_1-1739803034129.png

 

in incident i want whenever i select BU  and when i reference to u_deep its should show all records where BU is HR , but right now its showing single records 

Aarushi1991_2-1739803233540.png

 

 

Here is my refer qualifier on u_deep: javascript: new showdeparment().getdepartment(current.u_business_unit);

 

 

Script include 

 

var showdeparment = Class.create();
showdeparment.prototype = {
    initialize: function() {},

   
getdepartment:function(bussinessUnit){
gs.info("Script incldue state:");
var deparmentlist=[];


var deparemt= new GlideRecord("u_customer_table");
deparemt.addQuery('u_bu',bussinessUnit);
deparemt.query();
while(deparemt.next()){

    deparmentlist.push(deparemt.sys_id);
    gs.info("deparment"+deparmentlist);
   
}
return 'sys_idIN'+deparmentlist;

},
    type: 'showdeparment'
};
 
 
 
This is log for gs.info("deparment"+deparmentlist);
 
Aarushi1991_3-1739803592755.png

 

Can anyone help me where its getting wrong i really wanted to know

 

 

 

2 ACCEPTED SOLUTIONS

maheshkhatal
Mega Sage

@Aarushi1991 If you are getting logged all the records correctly and Ref qualifier is correctly configure , then I think issue is that is is referring to the same object again. You need to make it string where you are adding those sys ids. See the changes I think is the root cause it is not returning all the records:

var deparemt= new GlideRecord("u_customer_table");
deparemt.addQuery('u_bu',bussinessUnit);
deparemt.query();
while(deparemt.next()){

    deparmentlist.push(deparemt.sys_id); //make it  deparmentlist.push(deparemt.sys_id.toString())
    gs.info("deparment"+deparmentlist);
   
}
return 'sys_idIN'+deparmentlist;

},
    type: 'showdeparment'
};

  Changing dept sys id as deparemt.sys_id.toString() will help resolve the issue.

Mark my response as helpful if it helped resolve your doubt.

Thank you,

Mahesh.

View solution in original post

@Aarushi1991 There is a concept called pass by value and pass by reference. Following line 

deparmentlist.push(deparemt.sys_id); 

 

pushes the reference (which is a memory address) of object deparemt.sys_id in array. With each array iteration the memory address for object deparemt.sys_id is overridden and finally with last iteration it is overriden by the memory address of the last object. To avoid this issue, either use .toString() or getValue() to extract the value and add it into the array. 

 

View solution in original post

8 REPLIES 8

maheshkhatal
Mega Sage

@Aarushi1991 If you are getting logged all the records correctly and Ref qualifier is correctly configure , then I think issue is that is is referring to the same object again. You need to make it string where you are adding those sys ids. See the changes I think is the root cause it is not returning all the records:

var deparemt= new GlideRecord("u_customer_table");
deparemt.addQuery('u_bu',bussinessUnit);
deparemt.query();
while(deparemt.next()){

    deparmentlist.push(deparemt.sys_id); //make it  deparmentlist.push(deparemt.sys_id.toString())
    gs.info("deparment"+deparmentlist);
   
}
return 'sys_idIN'+deparmentlist;

},
    type: 'showdeparment'
};

  Changing dept sys id as deparemt.sys_id.toString() will help resolve the issue.

Mark my response as helpful if it helped resolve your doubt.

Thank you,

Mahesh.

Thanks @maheshkhatal i want to understand this statement "I think issue is that is is referring to the same object again" 

**toString is used to convert obj into string,also in log  i am getting sys_id which is string value 

can you help me understanding it 

 

 

@Aarushi1991 There is a concept called pass by value and pass by reference. Following line 

deparmentlist.push(deparemt.sys_id); 

 

pushes the reference (which is a memory address) of object deparemt.sys_id in array. With each array iteration the memory address for object deparemt.sys_id is overridden and finally with last iteration it is overriden by the memory address of the last object. To avoid this issue, either use .toString() or getValue() to extract the value and add it into the array. 

 

Thanks @Sandeep Rajput  Something new i have learn today , i really appreciate your Explanation