How to Get Work-type ID from an Event

When a plan is triggered, the event object (ev) carries data about the event, such as the related sharedo id. It may be useful to enrich this information with further information about the work type.

In this example you will get a list of all participants with the creator role and put the id of the first one (there should only be one) into your context object so it can be used through the life of the plan.

  1. By the end of this section your main step (starting step) should look like this.
  2. In the main function - underneath where you have placed in your line to capture the sharedoId from the event - add in the following snippet.
    The snippet gets a list of all participants on the work type with a role of 'creator'. It then looks for the first one in the lists and puts the participant id into the context object for later use.
    If it can't find a creator then a warning is logged.
var participants = Helpers.convertArray(ev.Data.sharedo.participants.ToList());var creators = participants.filter(x => x.roleSystemName === "creator");
if (creators.length > 0) {
//ctx.creatorId is the id of the participant
//use this in your step
ctx.creatorId = creators[0].odsId;
log.Information(`Found creator `);
} else {
log.Warning("Unable to find creator");
}