Announcement

Collapse
No announcement yet.

Sending SMS to Multiple Phone Numbers from Lead Records

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sending SMS to Multiple Phone Numbers from Lead Records

    Hello developers,
    I have multiple email addresses and phone numbers associated with my leads. I need to send emails or SMS messages to the phone numbers listed in the "Lead Phone Number" field. However, I've encountered an issue when trying to send SMS messages through a workflow. I attempted to send SMS messages using the "Lead Phone" attribute in the payload, but the SMS is only being sent to the primary phone number.
    How can I send SMS messages to all the numbers listed in the "Lead Phone" field?
    Similarly, when I add a foreign field to another entity, only the primary phone number is being fetched. How can I retrieve all the numbers listed in the "Phone" field?




  • #2
    Hi sapyantuk,

    For the solution that I propose to you, you need to create an API User and give him the access to read the Lead records. In the Send HTTP Request action change your instance URL and X-Api-Key.

    Manual workflow for sending emails to all the Lead email addresses:

    Click image for larger version  Name:	image.png Views:	0 Size:	54.7 KB ID:	99309
    Click image for larger version  Name:	image.png Views:	0 Size:	66.0 KB ID:	99310

    Formula script:
    Code:
    $leadId = workflow\targetEntity\attribute('id');
    
    $emailAddressData = json\retrieve($_lastHttpResponseBody, 'emailAddressData');
    $emailAddressLength = array\length($emailAddressData);
    
    
    
    // START: get email addresses array
    
    $i = 0;
    
    while ($i < $emailAddressLength) {
    
       $emailAddress = json\retrieve($_lastHttpResponseBody, string\concatenate('emailAddressData.', $i, '.emailAddress'));
       $emailAddressesList = array\push($emailAddressesList, $emailAddress);
    
       $i = $i + 1;
    }
    
    // STOP: get email addresses array
    
    
    
    
    // START: send email to all Lead email addressess
    
    $i = 0;
    
    while ($i < $emailAddressLength) {
        
        $emailId = record\create(
            'Email',
            'subject', 'Test',
            'status', 'Draft',
            'to', array\at($emailAddressesList, $i)
            );
            
        ext\email\send($emailId);    
        
        $i = $i + 1;
        
    }
    
    // START: send email to all Lead email addressess
    ​

    Manual workflow for sending SMS to all the Lead phone numbers:

    Click image for larger version  Name:	image.png Views:	0 Size:	56.7 KB ID:	99311
    Click image for larger version

Name:	image.png
Views:	51
Size:	62.7 KB
ID:	99313​​


    Formula script:
    Code:
    $leadId = workflow\targetEntity\attribute('id');
    
    $phoneNumberData = json\retrieve($_lastHttpResponseBody, 'phoneNumberData');
    $phoneNumberLength = array\length($phoneNumberData);
    
    // START: get phone numbers array
    
    $i = 0;
    
    while ($i < $phoneNumberLength) {
    
       $phoneNumber = json\retrieve($_lastHttpResponseBody, string\concatenate('phoneNumberData.', $i, '.phoneNumber'));
       $phoneNumbersList = array\push($phoneNumbersList, $phoneNumber);
    
       $i = $i + 1;
    }
    
    // STOP: get phone numbers array
    
    
    
    
    // START: send SMS to all Lead phone numbers
    
    $i = 0;
    
    while ($i < $phoneNumberLength) {
    
        $smsId = record\create(
        'Sms',
        'to', array\at($phoneNumbersList, $i),
        'body', 'This is a test.',
        'status', 'Draft'
        );
            
        ext\sms\send($smsId);  
        
        $i = $i + 1;
        
    }
    
    // STOP: send SMS to all Lead phone numbers​
    Last edited by lazovic; 11-01-2023, 01:54 PM.

    Comment

    Working...
    X