Assignment group is not getting populated

SumajRajNk
Tera Contributor

I'm using the below script in assignment group field of catalog task in Flow designer for fetching the assignment group.  The v03_work_group & v05_affected_cis are single line text variables and are non mandatory. 

 

When I'm giving no input to those end user variables, then the assignment group is getting populated in task according to the requested for user's request management group. 

Also its getting populated when I'm giving a valid assignment group name which is under requested for users company domain for v03_work_group.

 

But its not getting populated when I'm giving a valid assignment group name which is not under requested for users company domain or when I'm giving an invalid name for v03_work_group.

 

The goal is the assignment group which I'm giving for v03_work_group should be populated in assignment group if its a valid group despite of the domain. If I'm giving any invalid entry then only it should get assigned to requested for user's request management group. 

 

What changes should I make in the script? Is it a limitation of flowdesigner ? 

 

 

var groupName = fd_data._1__get_catalog_variables.v03_work_group.toString();
var ciName = fd_data._1__get_catalog_variables.v05_affected_cis.toString();
var assign_group = "";

if (groupName !=""){
    var groupGR = new GlideRecord('sys_user_group');
    groupGR.addQuery('name', groupName);
    groupGR.query();
    if (groupGR.next()) {
        assign_group = groupGR.sys_id.toString();
        }return assign_group;
        }
        else if (ciName && !assign_group) {
            var ciGR = new GlideRecord('cmdb_ci');
            ciGR.addQuery('name', ciName);
            ciGR.query();
            if (ciGR.next() && ciGR.managed_by){
                assign_group = ciGR.managed_by.toString();
                }return assign_group;
                }
                else if (!assign_group){
                    var requestedFor = fd_data.trigger.request_item.request.requested_for;
                    if (requestedFor && requestedFor.company) {
                        var atdGR = new GlideRecord('u_account_team_directory');
                        atdGR.addQuery('u_company',requestedFor.company.toString());
                        atdGR.query();
                        if (atdGR.next() && atdGR.u_request_management_group) {
                            assign_group = atdGR.u_request_management_group.toString();
                            }return assign_group;
                            }
                            }
 
Solutions for this issue is highly appreciated
1 ACCEPTED SOLUTION

Ehab Pilloor
Mega Sage

Hi @SumajRajNk,

 

I see that if group name is not empty it executes a glide record for garbage value too. You need to remove first if condition and do a GlideRecord check, if GlideRecord is not returned, then do other checks, also keep else condition as fallback so that assignment group returns Service Management group.

Bonus: add queryNoDomain() for cross domain assignment.

Try this script:

var groupName = fd_data._1__get_catalog_variables.v03_work_group.toString();
var ciName = fd_data._1__get_catalog_variables.v05_affected_cis.toString();
var assign_group = "";

    var groupGR = new GlideRecord('sys_user_group');
    groupGR.addQuery('name', groupName);
    groupGR.queryNoDomain();
    if (groupGR.next()) {
        assign_group = groupGR.sys_id.toString();
        return assign_group;
    }
 else if (ciName != "") {
    var ciGR = new GlideRecord('cmdb_ci');
    ciGR.addQuery('name', ciName);
    ciGR.addQuery('managed_by', '!=', '');
    ciGR.queryNoDomain();
    if (ciGR.next()) {
        assign_group = ciGR.managed_by.toString();
        return assign_group;
    }
} else {
    var requestedFor = fd_data.trigger.request_item.request.requested_for;
    if (requestedFor && requestedFor.company) {
        var atdGR = new GlideRecord('u_account_team_directory');
        atdGR.addQuery('u_company', requestedFor.company.toString());
        atdGR.queryNoDomain();
        if (atdGR.next() && atdGR.u_request_management_group) {
            assign_group = atdGR.u_request_management_group.toString();
        }
        return assign_group;
    }
}

 

 

View solution in original post

9 REPLIES 9

Mark Manders
Mega Patron

Put some logs in it to see where it's failing. It would be easier to just put it in as a variable, right? Have them choose the group instead of letting them type it?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@SumajRajNk 

what debugging did you do?

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

I have tried making lots of changes to that script and it was't working, result was the same and goal wasn't acheived

@SumajRajNk 

that's fine, but what are your findings when you added logs?

please share that.

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