Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Setting Assignment Group based on Idea Category

Kumari Divya
Giga Guru

Hi @LL i need to set the assignment group and assigned to based on the Idea category.

KumariDivya_0-1706768282067.png

 

KumariDivya_1-1706768282068.png

 

I tried to search the category field in form layout but it is not present taking the value from the portal(server). I tried to create 1 business rule for fetching the value from the table -im_m2m_idea_category  but it is not working.Table -im_m2m_idea_category mapped the idea and category table.

var gr = new GlideRecord('im_m2m_idea_category');
gr.addQuery('idea', current.short_description);
gr.query();
while(gr.next()) {
gs.addInfoMessage(current.short_description);
gs.addInfoMessage(gr.getValue('category_id'));
if(gr.getValue('category_id') == 'ITBM') {
current.assignment_group = "Default name1";
current.assigned_to = "TEST1";
current.update();
} else if (gr.getValue('category_id')== 'ITSM') {
current.assignment_group = "Default name2";
current.assigned_to = "TEST2";
current.update();
} else if (gr.getValue('category_id')== 'HR') {
current.assignment_group = "Default name3";
current.assigned_to = "Test3";
current.update();
}
}

})(current, previous);

 

Thanks in advance.

8 REPLIES 8

Hi @Aniket Chavan 

Let me try this.

Hi @Aniket Chavan 

I tried the same script on Table -'im_m2m_idea_category' and fetch the value from idea table.

Now its working fine.

 

 

Okay, Great to hear that🤗, if my response helped you then please consider marking my solution as helpful and accept as well and close the thread , so that it could help the future readers.

 

Regards,

Aniket

Aniket Chavan
Tera Sage
Tera Sage

Hello @Kumari Divya ,

Please give a try to the script below and let me know how it works for you.

(function executeRule(current, previous) {
    var gr = new GlideRecord('im_m2m_idea_category');
    gr.addQuery('idea', current.short_description);
    gr.query();

    while (gr.next()) {
        var categoryId = gr.getValue('category_id');
        gs.log("Idea: " + current.short_description);
        gs.log("Category ID: " + categoryId);

        if (categoryId == 'ITBM') {
            current.assignment_group = "Default name1";
            current.assigned_to = "TEST1";
        } else if (categoryId == 'ITSM') {
            current.assignment_group = "Default name2";
            current.assigned_to = "TEST2";
        } else if (categoryId == 'HR') {
            current.assignment_group = "Default name3";
            current.assigned_to = "Test3";
        }

        gs.log("Setting Assignment Group: " + current.assignment_group);
        gs.log("Setting Assigned To: " + current.assigned_to);

        current.update();
        gs.log("Record updated successfully");
    }
})(current, previous);

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.

 

Thanks,

Aniket