3

I have a custom activity in marketing automation. Then I try to get phone number when user IContactProcessingContext, but context.Contact.GetFacet() return null. Any suggestions as to what I need to do in order to get the Phone Number from PhoneNumberList facet ?

I'm using Sitecore 9.0.2.

My controller:

public class SendSMS : IActivity
{
    public IActivityServices Services { get; set; }
    // Parameters
    public string Message { get; set; }
    public ActivityResult Invoke(IContactProcessingContext context)
    {
        string preferredMail = string.Empty;            

        ////get email facet from context contact            



        PhoneNumberList facet = context.Contact.GetFacet<PhoneNumberList>();

        ////exiting activity with failure
        if (facet == null || facet.PreferredPhoneNumber == null)
        {
            return (ActivityResult)new Failure("The Phone Number list Facet Has Not Been Set Successfully");
        }
        string phoneNumber = facet.PreferredPhoneNumber.Number;
        //instantiating email service without DI for simplicity
        var smsService = new SmsService();
        if (!smsService.SendSms(phoneNumber, this.Message))
        {
            return (ActivityResult)new Failure("Failed to send sms message");
        }

        return (ActivityResult)new SuccessMove("true");
    }
2
  • Phone numbers facet isn't loaded by default. There is config to add this. I'll answer properly later. Oct 29, 2019 at 8:59
  • I look around it and find in the folder : xconnect_root\App_data\jobs\continuous\AutomationEngine\App_Data\Config\sitecore\MarketingAutomation\sc.MarketingAutomation.ContactLoader. But when I add PhoneNumberList the maengine is error. Is it right?
    – ThinhLe
    Oct 29, 2019 at 9:15

3 Answers 3

0

The PhoneNumbers Facet is not included as a default facet expand options in MA

I think I found this for you. The xml configuration file sc.MarketingAutomation.ActivityTypes.xml has a section called IncludeFacetNames that defines what facets to include when the contact is created. So if you update the section to include the PhoneNumberList facet, it will be there by default.

<Options>
    <IncludeFacetNames>
        <Facet1>Emails</Facet1>
        <Facet2>ListSubscriptions</Facet2>
        <Facet3>ContactBehaviorProfile</Facet3>
    </IncludeFacetNames>
    <ExcludeFacetNames />
</Options>

to

<Options>
    <IncludeFacetNames>
        <Facet1>Emails</Facet1>
        <Facet2>ListSubscriptions</Facet2>
        <Facet3>ContactBehaviorProfile</Facet3>
        <Facet4>PhoneNumbers</Facet4>
    </IncludeFacetNames>
    <ExcludeFacetNames />
</Options>

The file can be located here in the root of your xconnect site.

\xconnect\App_Data\jobs\continuous\AutomationEngine\App_Data\Config\sitecore\MarketingAutomation\sc.MarketingAutomation.ActivityTypes.xml

Now when the contact loads, phone numbers are there.

enter image description here

The Proper way to patch a config in MA service

Rathen than edit the out of the box xml config files. It is better to patch them. Here is how you do it.

In the folder \xconnect\App_Data\jobs\continuous\AutomationEngine\App_Data\Config\sitecore\MarketingAutomation\ create a folder called custom. In that folder create a file called sc.MarketingAutomation.ActivityTypes.xml. It must be named exactly the same as the file you are patching. In that file, place the xml below and save. Restart the MA windows service.

<Settings>
  <Sitecore>
    <XConnect>
      <MarketingAutomation>
        <Engine>
          <Services>
            <MarketingAutomation.Loading.ContactFacetsConfigurator>
              <Options>
                <IncludeFacetNames>
                    <Facet4>PhoneNumbers</Facet4>
                </IncludeFacetNames>
               </Options>
            </MarketingAutomation.Loading.ContactFacetsConfigurator>
          </Services>
        </Engine>
       </MarketingAutomation>
     </XConnect>
   </Sitecore>
</Settings>
5
  • I try to inherit BaseActivity but it's changed in Sitecrore 9. I see the document here. doc.sitecore.com/developers/90/sitecore-experience-platform/en/….
    – ThinhLe
    Oct 28, 2019 at 3:12
  • What type are you inheriting? The inherited type should inherit from BaseActivity at some point.
    – Chris Auer
    Oct 29, 2019 at 1:04
  • I inherit from IActivity, same with doc I comment above. I will update my class in my question
    – ThinhLe
    Oct 29, 2019 at 7:46
  • @ThinhLe I found the answer for your issue
    – Chris Auer
    Oct 30, 2019 at 2:49
  • Yes, it is. You save my day. Thank you too much Chris
    – ThinhLe
    Oct 30, 2019 at 3:56
1

You need to include the PhoneNumberList facet which has a facet key of PhoneNumbers. You can patch it in by creating a new file that loads after the xconnect_root\App_data\jobs\continuous\AutomationEngine\App_Data\Config\sitecore\MarketingAutomation\sc.MarketingAutomation.ContactLoader

<Settings>
  <Sitecore>
    <XConnect>
      <MarketingAutomation>
        <Engine>
          <Services>
            <MarketingAutomation.Loading.ContactFacetsConfigurator>
              <Options>
                <IncludeFacetNames>
                  <PhoneNumbers>PhoneNumbers</PhoneNumbers>
                </IncludeFacetNames>
              </Options>
            </MarketingAutomation.Loading.ContactFacetsConfigurator>
          </Services>
        </Engine>
      </MarketingAutomation>
    </XConnect>
  </Sitecore>
</Settings>
6
  • Can the patch fie have any name? I thought that patch file needed the same name as the file you are patching. Just loaded later. I guess I can try this.
    – Chris Auer
    Oct 30, 2019 at 3:07
  • It can have any name, but I think it just needs to be alphabetically named so it is loaded later than sc.MarketingAutomation.ContactLoader. Oct 30, 2019 at 3:22
  • Just tried it 10 ways to sunday. Has to load after the original (so put it in a folder under the current xml config). And MUST be named exactly the same. I tried aaaa.xml and zzzzz.xml. Neither worked. When I named it sc.MarketingAutomation.ActivityTypes.xml again, worked again.
    – Chris Auer
    Oct 30, 2019 at 3:39
  • I have mine in the MarketingAutomation folder named sc.SendSms.ActivityServices.xml (it also contains some other definitions). Sitecore 9.1.1. Oct 30, 2019 at 3:50
  • Hmmm. I’m in 9.1. Weird part is my custom activity works with any file name. But not the phone facet.
    – Chris Auer
    Oct 30, 2019 at 3:51
1

After creating the Activity Type class and registering your custom activity type and services in Marketing Automation, you'll need to register the PhoneNumber facet in Marketing Automation.

By Default, below OOTB facets are registered under Markating Automation:

   <IncludeFacetNames>
          <Addresses>Addresses</Addresses>
          <ConsentInformation>ConsentInformation</ConsentInformation>
          <Emails>Emails</Emails>
          <EngagementMeasures>EngagementMeasures</EngagementMeasures>
          <ListSubscriptions>ListSubscriptions</ListSubscriptions>
          <Personal>Personal</Personal>
          <InteractionsCache>InteractionsCache</InteractionsCache>
    </IncludeFacetNames>

Now, To register the other contact facets in ContactLoader config patch. Create a new patch file sc.MarketingAutomation.ContactLoader.xml at below path <path_to_xconnect>\App_Data\jobs\continuous\AutomationEngine\App_Data\Config\sitecore\MarketingAutomation_patch

(Note: I've created a new folder named MarketingAutomation_patch to include all patches for marketing automation under this folder.)

<Settings>
 <!--
   Marketing Automation contact loader configuration
-->
 <Sitecore>
   <XConnect>
     <MarketingAutomation>
       <Engine>
         <Services>
           <MarketingAutomation.Loading.ContactFacetsConfigurator>
             <Options>
               <IncludeFacetNames>
                 <PhoneNumbers>PhoneNumbers</PhoneNumbers>
               </IncludeFacetNames>
             </Options>
           </MarketingAutomation.Loading.ContactFacetsConfigurator>
         </Services>
       </Engine>
     </MarketingAutomation>
   </XConnect>
 </Sitecore>
</Settings>

I've covered all the steps in details to create a new custom action in Marketing Automation and deployment here: https://sitecorewithraman.wordpress.com/2021/04/25/sitecore-marketing-automation-custom-action-part-iii/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.