script for assignment groups

nyrguy451
Tera Contributor

Hello all,

I have a script that will assign a specific assignment group to the REQ & RITM, this is a before script on the sc_request table.

What I need to do is be able to query if the requester is from a specific company and if so the assignment group would be different for this purpose we will call the company ACME and the assignment group EQ.  Additionally, if the requestor is not from ACME then the rest of this works. so in theory

if - requestor = ACME 

assign to = EQ

else - assign to Service Desk (which is part of the original script)

Below is the current code and will need to add the new portion, I am not a developer and am kind of in a bind. Any and all help will be so very appreciated.

(function executeRule(current, previous /*null when async*/) {
	var gr = new GlideRecord('sc_req_item');
	gr.addQuery('request', current.sys_id);
	gr.query();
	
	if (gr.getRowCount() == 1) {
		gr.next();
		
		if (gr.assignment_group != "") {
			current.assignment_group = gr.assignment_group;
		} else {
			current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
		}
		
		current.short_description = gr.cat_item.name;
		current.description = gr.variables.description;
	} else if (gr.getRowCount() > 1) {
		gr.next();
		var assignment_group = gr.assignment_group;
		var same_group = true;
		var description = "Catalog Items:\n";
		
		do {
			description += gr.cat_item.name + "\n";
			if (!(assignment_group == gr.assignment_group) && same_group) {
				same_group = false;
			}
		} while (gr.next());
		
		if (same_group) {
			current.assignment_group = assignment_group;
			current.short_description = "Multi Item Request";
			current.description = description;
		} else {
			current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
			current.short_description = "Unknown Service Request";
		}
	} else {
		current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
		current.short_description = "Unknown Service Request";
	}
})(current, previous);
1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Hi can you try this and let me know. Added the bold lines to check if requestor company is ACME set group to EQ. If requestor company is NOT ACME follow the current script

(function executeRule(current, previous /*null when async*/) {
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('request', current.sys_id);
    gr.query();
    
    if (gr.getRowCount() == 1) {
        gr.next();
        
        if (gr.assignment_group != "" && gr.requested_for.company != 'companysysid') {
            current.assignment_group = gr.assignment_group;
        } 
        else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }
        else {
            current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
        }
        
        current.short_description = gr.cat_item.name;
        current.description = gr.variables.description;
    } 
    else if (gr.getRowCount() > 1) {
        gr.next();
        var assignment_group = gr.assignment_group;
        var same_group = true;
        var description = "Catalog Items:\n";
        
        do {
            description += gr.cat_item.name + "\n";
            if (!(assignment_group == gr.assignment_group) && same_group && gr.requested_for.company != 'companysysid') {
                same_group = false;
            }
        } while (gr.next());
        
        if (same_group) {
            current.assignment_group = assignment_group;
            current.short_description = "Multi Item Request";
            current.description = description;
        } 
        else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }else {
            current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
            current.short_description = "Unknown Service Request";
        }
    }
    else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }
    else {
        current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
        current.short_description = "Unknown Service Request";
    }
})(current, previous);

Regards
Harish

View solution in original post

2 REPLIES 2

Harish KM
Kilo Patron
Kilo Patron

Hi can you try this and let me know. Added the bold lines to check if requestor company is ACME set group to EQ. If requestor company is NOT ACME follow the current script

(function executeRule(current, previous /*null when async*/) {
    var gr = new GlideRecord('sc_req_item');
    gr.addQuery('request', current.sys_id);
    gr.query();
    
    if (gr.getRowCount() == 1) {
        gr.next();
        
        if (gr.assignment_group != "" && gr.requested_for.company != 'companysysid') {
            current.assignment_group = gr.assignment_group;
        } 
        else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }
        else {
            current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
        }
        
        current.short_description = gr.cat_item.name;
        current.description = gr.variables.description;
    } 
    else if (gr.getRowCount() > 1) {
        gr.next();
        var assignment_group = gr.assignment_group;
        var same_group = true;
        var description = "Catalog Items:\n";
        
        do {
            description += gr.cat_item.name + "\n";
            if (!(assignment_group == gr.assignment_group) && same_group && gr.requested_for.company != 'companysysid') {
                same_group = false;
            }
        } while (gr.next());
        
        if (same_group) {
            current.assignment_group = assignment_group;
            current.short_description = "Multi Item Request";
            current.description = description;
        } 
        else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }else {
            current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
            current.short_description = "Unknown Service Request";
        }
    }
    else if(gr.requested_for.company == 'companysysid'){
            current.assignment_group = 'YourgroupSYSID'; // YourgroupSYSID
        }
    else {
        current.assignment_group = '9b3ac0bd1b2a28503fcf3224cc4bcb40'; // Service Desk
        current.short_description = "Unknown Service Request";
    }
})(current, previous);

Regards
Harish

Thank you very much this worked out exactly the way it should.