Mention Assigned Users on a field update
Mention Assigned Users when the Name or Planned Dates of an Epic are updated
{
"pipeline": [
{
"type": "source:targetprocess:EntityChanged",
"entityTypes": [
"epic"
],
"modifications": {
"created": false,
"deleted": false,
"updated": [
"Name",
"PlannedEndDate",
"PlannedStartDate"
]
}
},
{
"type": "action:JavaScript",
"script": "const api = context.getService('targetprocess/api/v2');\n\nconst changedFields = args.ChangedFields.filter(x => x !== 'ModifyDate' && x !== 'LastEditor');\n\n//Changed fields with their Previous and Current Values\nconst changes = changedFields.map(field => { \n return {'field': field, 'previousValue': args.Previous[field], 'currentValue': args.Current[field]}\n});\n\nconst changesMessage = changes.reduce((acc, value) => `${acc} \"${value.field}\" was modified from \"${value.previousValue}\" to \"${value.currentValue}\",`, '');\n\n//Get current entity Assignments\nconst assignments = await api.queryAsync('Assignment', {\n where: `assignable.id==${args.ResourceId}`,\n select: '{userid:user.id,useremail:user.email,userfullname:user.fullname,userlogin:user.login}'\n});\n\nif (!assignments || !assignments.length) {\n console.log('No assignments found. Exiting');\n return;\n}\n\n//Remove duplicates\nconst users = assignments.reduce((acc, value) => acc.some(user => user.userid === value.userid) ? acc : acc.concat(value), []);\n//Format mentions\nconst userMentions = users.reduce((acc, value) => `${acc} @user:${value.userlogin}[${value.userfullname}]`, '');\n\nreturn {\n command: 'targetprocess:CreateResource',\n payload: {\n resourceType: 'Comment',\n fields: {\n General: { Id: args.Current.Id },\n Description: `Fields were updated by ${args.Author.FullName}: ${changesMessage} CC${userMentions}`\n }\n }\n};\n"
}
]
}
Result:
Updated about 1 year ago