Workflow for Contact Roles Attached to Opportunities

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bgpus
    Junior Member
    • Dec 2020
    • 10

    #1

    Workflow for Contact Roles Attached to Opportunities

    I'm trying to build a workflow in that reads the attached Contacts to the Opportunities, specifically their contactRole. I have "Contact Role equals Role" in the conditions, but it's not reading this. Is there a better workaround for this?
  • lazovic
    Super Moderator
    • Jan 2022
    • 1046

    #2
    Hi bgpus,

    Consider using the Execute Formula Script action with the following formula script:
    Code:
    // CONDITIONS
    
    $oppId = workflow\targetEntity\attribute('id');
    $contactsIds = record\findRelatedMany('Opportunity', $oppId, 'contacts', 100, 'createdAt', 'desc');
    
    $i = 0;
    
    while ($i < array\length($contactsIds)) {
        $contactId = array\at($contactsIds, $i);
        $role = record\relationColumn('Opportunity', $oppId, 'contacts', $contactId, 'role');
        $roles = array\push($roles, $role);
        
        $i = $i + 1;
    }
    
    // ACTIONS
    
    if (array\includes($roles, 'Landlord')) {
        record\update('Opportunity', $oppId, 'description', 'There is related contact with  Landlord role.')
    } else {
        record\update('Opportunity', $oppId, 'description', 'There is not related contact with Landlord role.')
    }

    Comment

    • bgpus
      Junior Member
      • Dec 2020
      • 10

      #3
      Got it - thank you!

      Comment

      • bgpus
        Junior Member
        • Dec 2020
        • 10

        #4
        I am assuming this will only work in BPM that executes after save? I am forced to refresh to view.

        Comment

        • lazovic
          Super Moderator
          • Jan 2022
          • 1046

          #5
          bgpus,

          This script will work with any type of trigger in the workflow. If you want to use it in a flowchart (BPM), then you need to change the word "workflow" to "bpm" one in the formula functions.

          Comment

          Working...