Update assigned to field using transform map

ram11vrnr
Tera Contributor

Hi,

I have created a transform map to update assigned to field in one of my custom table. created field mapping for the same and assigned to updated correctly.

 

Now i want to restrict if the mentioned user is part of the assignment group then only it should update the assigned to field. if the mentioned user is not part of assignment group, it should ignore.

1 REPLY 1

Rahul Kumar17
Tera Guru

Hi @ram11vrnr ,

 

To restrict the update of the "assigned to" field based on the user's membership in the assignment group, you can add a script include that checks if the user is a member of the group before updating the field. Here's an example:

  1. Create a script include with the following code to check if the user is a member of the assignment group:

var MyScriptInclude = Class.create();
MyScriptInclude.prototype = {
initialize: function() {
},

isUserMemberOfGroup: function(userId, groupId) {
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group', groupId);
gr.query();
return gr.hasNext();
}
}

This script include defines a method isUserMemberOfGroup that takes a user ID and a group ID as parameters, and checks if the user is a member of the group by querying the sys_user_grmember table.

  1. In the field mapping for the "assigned to" field in the transform map, add a script to call the isUserMemberOfGroup method and update the field only if the user is a member of the assignment group. Here's an example:

// Instantiate the script include
var scriptInclude = new MyScriptInclude();

// Get the user ID and assignment group ID from the source field values
var userId = source.u_user.toString();
var assignmentGroupId = source.u_assignment_group.toString();

// Check if the user is a member of the assignment group
if (scriptInclude.isUserMemberOfGroup(userId, assignmentGroupId)) {
// Update the target field with the user ID
target.assigned_to = source.u_user;
}

 

Thanks,

Rahul Kumar

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar