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'])

5 comments

  1. Any way to further filter our that a Note must contain 1) an attachment 2) Attachment type must be PDF?

    1. Hi Lucas,
      The expression @equals(triggerOutputs()?[‘body/isdocument’],true) relates to must contain an attachment. You could add an extra trigger condition for the file type: @endsWith(triggerOutputs()?[‘body/filename’],’.pdf’)

Leave a Reply

Your email address will not be published. Required fields are marked *