Send personal Slack notifications about assignments

This rule will take SlackID from the corresponding custom field of the User in Targetprocess. Then rule sends a message to this SlackID. If such a User doesn`t exist in Slack or SlackID is incorrect then the rule catches an exception and sends a notification to #slack-test channel.



Users should have a custom field SlackID


How to apply this rule?



Warning: sample URLs!

Please make sure to replace with your Slack Webhook URL and with your Targetprocess URL

    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst assignments = await api.queryAsync(\"Assignment\", {\n  select: \"{,slackId:generalUser.slackId,userId:generalUser.Id}\",\n  where: `id=${args.ResourceId}`\n});\nif (!assignments.length) { return; }\n\nconst slackId = assignments[0].slackId;\nconst type = assignments[0].type;\nconst link = `<${args.Current.Assignable.Id}|${args.Current.Assignable.Name}>`;\n\nconst http = context.getService('http');\n\ntry {\n  await http.postAsync('', {\n    body: {\n      \"text\": `${args.Author.FullName} has assigned you on ${type} ${link}`,\n      \"channel\": slackId,\n      \"icon_emoji\": \":muscle:\",\n      \"username\": \"TP\"\n    }\n  });\n}\n\ncatch (error) {\n  await http.postAsync('', {\n    body: {\n      \"text\": `User #${assignments[0].userId} has incorrect SlackID `,\n      \"channel\": slackId,\n      \"icon_emoji\": \":muscle:\",\n      \"username\": \"TP\"\n    }\n  });\n  console.log(error);\n}"