Filter based on assignment group in sys_journal_field table.

VasukiS
Tera Guru

Hi Team,

I need to filter the data based on a particular assignment group from the HR Core Case table.

Since the element ID does not have one of the options, I have decided to write a script include and add those in the element ID filter.

I have tried below script, but it is showing as undefined.

Client callable is yes, and the script is active.

var getelementID = Class.create();
getelementID.prototype = {
    initialize: function() {
    },
    
    getelementID: function() {
        var arrUser = [];
        var gr = new GlideRecord('sn_hr_core_case');
        gr.addQuery('assignment_group', 'e26a8785dbd5c150dbc71a8c139619a9');
		gr.addQuery('state',1);
        gr.query();
        while (gr.next()) {
            arrUser.push(gr.sys_id.toString());
        }
        gs.info('getelementID: ' + arrUser); // Log the array for debugging
        return arrUser;
    },
    
    type: 'getelementID'
};

 Filter script : javascript:getelementID.getelementID()

 

Name of the script include is getelementID.

 

VasukiS_0-1747415466799.png

VasukiS_1-1747415526927.png

Anyone please help me how to achieve this ?

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@VasukiS 

make these changes and see if it works

The Element ID field is char type and not string and hence it won't be supporting IS ONE OF operator and hence it won't work

AnkurBawiskar_0-1747832537814.png

 

You can use left nav module and then add this in the filter condition

Script Include: The name of script include and function I made different

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

    getRecords: function() {
        var arrUser = [];
        var gr = new GlideRecord('sn_hr_core_case');
        gr.addQuery('assignment_group', 'e26a8785dbd5c150dbc71a8c139619a9');
        gr.addQuery('state', 1);
        gr.query();
        while (gr.next()) {
            arrUser.push(gr.sys_id.toString());
        }
        return arrUser.toString();
    },

    type: 'getelementID'
};

Then call it like this in left nav module and see

Element ID [IS ONE OF] javascript: new getelementID().getRecords();

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Chaz
Tera Guru

In your condition you need to initialize the script include so it will need to be
javascript: new getelementID()

@Chaz I have tried these method but still I am getting error it is populating as [object object].

I have modified the script include with few other methods but same issue. 

 

VasukiS_0-1747739925038.png

 

Hello, it's probably because it's returning the array.

Try returning it as a string

 

return arrUser.toString();

yes i have tried to change the script with few method but showing the same issue.