Workflow Catalog Task Advanced Script Help

jonGriff
Tera Expert

Hello,

I'm trying to add some scripting to a catalog task created by a hardware catalog item's workflow. I would like the catalog task to be assigned to an individual based on the task's associated computer > scope data (a reference table used to mark which group a computer is managed by).  For example, once the requested computer is delivered, a new catalog task is created, this task should be routed based on the associated computers assigned scope.  If the "scope" is assigned to "Enrollment", then check if the Enrollment scope provisions their own assets, if true, assign to the managed by staff member, else, route to the OIT backup.

Any input is appreciated! Thanks!

var compScope = task.request_item.u_task_computer.u_asset_scope; //obtains the task's associated computer scope

var grAssignedCompScope = new GlideRecord('u_asset_scope'); //GR to asset scope table
grAssignedCompScope.addQuery('sys_id', compScope);
grAssignedCompScope.setLimit(1);
grAssignedCompScope.query();

while (grAssignedCompScope.next()) {
	var provisionsAssets = grAssignedCompScope.u_provisioning; //checks if the scope is managed by OIT
	var oitTech = grAssignedCompScope.u_oit_tech; //sets the scopes assigned OIT tech (tech support - username)
	var managedBy = grAssignedCompScope.u_managed_by; //sets who managed the scope (tech partner - username)
	//var managedByGroup = #### //do I need to do a lookup for the assignment group?
	
	if (provisionsAssets == 'True') {
		//task.assignment_group.setDisplayValue("managedByGroup);
		task.assigned_to.setDisplayValue(managedBy); //sets the tech partner staff, if u_provisioning is true
	} else {
		task.assignment_group.setDisplayValue("Technical Support");
		task.assigned_to.setDisplayValue(oitTech); //sets the tech support staff, if u_provisioning is false
	}
}
1 ACCEPTED SOLUTION

jonGriff
Tera Expert

I got the script working with the following:

var compScope = current.u_task_computer.asset.u_asset_scope; //obtains the task's associated computer scope

var grAssignedCompScope = new GlideRecord('u_asset_scope'); //GR to asset scope table
grAssignedCompScope.addQuery('sys_id', compScope);
grAssignedCompScope.setLimit(1);
grAssignedCompScope.query();

while (grAssignedCompScope.next()) {
	var provisionsAssets = grAssignedCompScope.u_provisioning; //checks if the scope is managed by the group
	var oitTech = grAssignedCompScope.u_oit_tech; //sets the scopes assigned IT tech
	var managedByGroup = grAssignedCompScope.u_managed_by.u_primary_group.getDisplayValue();
	
	if (provisionsAssets == true) {
		task.assignment_group.setDisplayValue(managedByGroup);
	} else {
		task.assignment_group.setDisplayValue("Technical Support");
		task.assigned_to.setDisplayValue(oitTech); //sets the IT tech support staff, if u_provisioning is false
	}
}

View solution in original post

3 REPLIES 3

ccajohnson
Kilo Sage

If this is part of a Catalog Task workflow Activity script, you may want to change the first line to point to the current record

var compScope = current.u_task_computer.u_asset_scope; //obtains the task's associated computer scope

jonGriff
Tera Expert

I got the script working with the following:

var compScope = current.u_task_computer.asset.u_asset_scope; //obtains the task's associated computer scope

var grAssignedCompScope = new GlideRecord('u_asset_scope'); //GR to asset scope table
grAssignedCompScope.addQuery('sys_id', compScope);
grAssignedCompScope.setLimit(1);
grAssignedCompScope.query();

while (grAssignedCompScope.next()) {
	var provisionsAssets = grAssignedCompScope.u_provisioning; //checks if the scope is managed by the group
	var oitTech = grAssignedCompScope.u_oit_tech; //sets the scopes assigned IT tech
	var managedByGroup = grAssignedCompScope.u_managed_by.u_primary_group.getDisplayValue();
	
	if (provisionsAssets == true) {
		task.assignment_group.setDisplayValue(managedByGroup);
	} else {
		task.assignment_group.setDisplayValue("Technical Support");
		task.assigned_to.setDisplayValue(oitTech); //sets the IT tech support staff, if u_provisioning is false
	}
}