Use multiple sys ids in one sys_property

gunashalini
Tera Contributor

I have added sys id of two groups in the system property - ITIL Role based Groups.

The scheduled job code should check the users added to the two groups and insert them to another table (u_itil_license_removal_candidates). Also it will check if records are already present in the another table. It;s working if I directly mention the name of groups in encodedQuery. But not working in this format.

What is the mistake I'm doing?

var gr = new GlideRecord('sys_user_grmember');
var groupSysIds = gs.getProperty('ITIL role based Groups').split(',');
gr.query();

while (gr.next()) {
	var user = gr.user.toString();
    for (var i = 0; i < groupSysId.length; i++) {
        var groupSysId = groupSysIds[i];

        var existingRecord = new GlideRecord('u_itil_license_removal_candidates');
        existingRecord.addQuery('u_user', user);
        existingRecord.addQuery('u_group.sys_id', groupSysId);
        existingRecord.query();

        if (!existingRecord.hasNext()) {
            license.initialize();
            license.u_user = user;
            license.u_group = groupSysId;
            license.u_license_removal_status = 'Pending Removal';
            license.insert();
        }
    }
}
10 REPLIES 10

Hi @gunashalini,

 

If above solution work for then, Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Thanks
Vijay Balotia