Scheduled Script Execution

system
Tera Contributor

Is there a better way to write it or a simpler way or a way to maintain it later?

var
gr= new GlideRecord('sys_user_grmember');
// Agroup
var tifi = gr.addQuery('group', 'ec6fb87747f1311047d9afcf016d438b');
// Bgroup
tifi .addOrCondition('group', 'Search group sysid');
//Cgroup
tifi .addOrCondition('group', 'Search group sysid');
gr.query();

if (gr.getRowCount() != 0) {
    gr.setWorkflow(false);
    gr.deleteMultiple();
}
6 REPLIES 6

Sandeep Rajput
Tera Patron
Tera Patron

@system You can choose to create a system property with following structure.

 

"{'GroupA': 'ec6fb87747f1311047d9afcf016d438b','GroupB: '<sys_id of group B>','GroupC': '<sys_id of group C>'}";

 

in your code you can access the property as follows.

 

var groupObj = JSON.parse(gs.getProperty('<property name>'));

var gr= new GlideRecord('sys_user_grmember');
// Agroup
var tifi = gr.addQuery('group', groupObj.GroupA);
// Bgroup
tifi .addOrCondition('group', groupObj.GroupB);
//Cgroup
tifi .addOrCondition('group', groupObj.GroupC);
gr.query();

if (gr.getRowCount() != 0) {
    gr.setWorkflow(false);
    gr.deleteMultiple();
}

Hope this helps.

 

Thank you very much for your answer

If you add it to a Property, if you add a new group later, should you add the Property first and then add the script? Will maintenance become complicated?

Yes, you nee to. That is an ideal way as you need to maintain things at one place instead of muliple places and help avoid hardcoding.

Thank you very much for your answer.

I don't want to use sysid to add directly, but I haven't thought of a better way. It's nerve-wracking, because the group searched here needs to be added with qualified users.