Checking for null

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MatLudlam
    Senior Member
    • Aug 2016
    • 288

    Checking for null

    Hi hope you can help.

    I have a new Entity type called Project. This has a many to many relationship with Contact.

    I often create new Projects in script from Opportunities (which also have a many to many relationship with Contact).

    When I create these new Projects in BPM I use the built in assignment tools thus:
    Click image for larger version

Name:	Contact Assignment.png
Views:	311
Size:	8.8 KB
ID:	56766

    And this works great, I get the same contacts on the Project as I have on the Opportunity.

    I now want to do this differently. On the Account entity I have a filed called "apContact" (the person that pays the bills) which I want to use if it exists.

    The pseudo code for what I want to do is:
    Code:
    if Account.apContact IS NULL then
       Project.contacts = Opportunity.contacts
    else
       Project.contacts = Account.apContact
    end if
    This poses 2 questions as I see it:
    1. How do I check to see if the apContact is NULL?
    2. There is a type mismatch on the 2nd assignment, because Project.contacts is a Link Multiple filed
    I have not tried the above yet, but would really appreciate your advice.

    Thanks.
  • yuri
    Member
    • Mar 2014
    • 8452

    #2
    Hi Mat,

    I suppose that the target entity type of your BPM process is Opportunity.

    In Create Related Record action > formula:

    Code:
    $accountId = bpm\targetEntity\attribute('accountId');
    $contactId = record\attribute('Account', $accountId, 'apContactId');
    
    ifThenElse(
        !$contactId,
        contactsIds = bpm\targetEntity\attribute('contactsIds'),
        contactsIds = list($contactId)
    );
    In this formula the target entity is switched to Project that is being created. That's why bpm\targetEntity\attribute is used to address the target entity of BPM process.

    Note, that I didn't have a chance to test this formula.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • MatLudlam
      Senior Member
      • Aug 2016
      • 288

      #3
      Thanks very much, looks good to me. I will give it a go.

      Comment

      Working...