Search code examples
servicenow

sys_id arrays to is one of not displaying records on my report


I am not able to display records on my report.

Report Source: Group Approval(sysapproval_group) table Condition:Sys Id - is one of - javascript: new GetMyGroupApprovals().getSysIds();

Script Include : MyGroupApproval Note : Active is checked, Accesible is all application score & Client callable unchecked

var GetMyGroupApprovals = Class.create();
GetMyGroupApprovals.prototype = {
    initialize: function() {
    },	
	getSysIds : function getMyGroupMembers(){		
		var ga = new GlideRecord('sysapproval_group');
		ga.addQuery('parent.sys_class_name', '=', 'change_request');		
		ga.query();
		gs.log("TotalRecords1 Before:: " + ga.getRowCount());
		var sysIdArray = [];
			while(ga.next()){					
					sysIdArray.push(ga.sys_id);			
			}		
		return sysIdArray;
		},
	
    type: 'GetMyGroupApprovals'
};

Kindly note that I have to achieve with script approach. I am not able to get records on my report.


Solution

  • This line is probably causing unexpected behavior: sysIdArray.push(ga.sys_id);

    ga.sys_id returns a GlideElement object, which changes for each of the iterations in the GlideRecord, so the contents of sysIdArray will just be an instance of the same object for each row in the result set, but the value will just be the last row in the set.

    You need to make sure you push a string to the array by using one of the following methods:

    sysIdArray.push(ga.sys_id+''); // implicitly call toString 
    sysIdArray.push(ga.getValue('sys_id')); // return string value