Set Trigger Conditions on Notes entity for upload of attachments in portal regarding specific entities

Posted by

Use case: when attachments are uploaded/added to a lead or opportunity record in a Dynamics 365 / Power Apps portal, a user wants to receive a notification by email. According to the settings attachments are added as Notes records to CDS. So we need to restrict the On Create trigger by setting the following trigger conditions:

@equals(triggerOutputs()?['body/isdocument'],true)
@equals(substring(triggerOutputs()?['body/notetext'],0,5),'*WEB*')
@not(empty(intersection(createArray('lead', 'opportunity'), createArray(triggerOutputs()?['body/objecttypecode']))))

So the trigger conditions will check if the note record is a document (file), and if the note description begins with the portal prefix ‘*WEB*’. A third condition will check whether the value of the objecttypecode attribute (similar to the regarding objectid type attribute) is part of a “list” of entities for what the trigger is needed, in this case lead and opportunity.

I just wanted to use the intersection function this time, but the contains function will do as well:
contains([<collection>], ‘<value>’)

@contains(createArray('lead', 'opportunity'), triggerOutputs()?['body/objecttypecode'])