web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to Define SMS Template same like Email template and instantiate through code.

(0) ShareShare
ReportReport
Posted on by 80

Hello Experts,

Is there any functionality to define SMS template where business can compose their SMSs and insert any field from contact and that populates in the actual message according to the Contact record, I mean same functionality like Email Template where we insert dynamic values like {!EntityLogicalName:FieldLogicalName;}.

Please suggest any OOB or lighter way to achieve this. Thanks in advance.

Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Kokulan Profile Picture
    18,054 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    I have had chance to check as well, so the template entity which is where the email templates are stored is not available for referencing or referenced entity, i have checked it via code.

    In your SMS template entity, you just have to keep the GUID or name of the template if its Uniqueue

    and use this to create email acivity for you

    github.com/.../CreateCustomEmailActivity.cs

    This will create email from Global templates, thats why I included this in my previous post

    Once you go the SMS Template entity with all the templates, you can associate any with Poll

    So i still think you can achieve what you want, only difference to my original suggestion is that instead of lookupl we are storing GUID but its a one time setup and guid is going to be used only in Code

    This has the text processing to replace placeholders and it works for related enities and all the data types : github.com/.../CreateCustomEmailActivity.cs

  • Shubh_K Profile Picture
    80 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Hi Kokulan, No email template is not available for lookup, that is the main problem. Seems we will have to create custom lookup control and populate the Email template list.

    I found this "Instantiating a email template" approach is better then "replacing the dynamic value using custom code" approach.

    But first one is also not straight forward to implement, but at-least  I won't have to hit my head to write logic to detect the placeholders, column name, their data types, fetch them from contact and again replacing the place holders with actual values, and I doubt how can I handle all scenarios.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Could you create a text field to keep the email template name if you can name the templates unique or since it's only four of them you can get their Guid and have that in the SMS template entity.  

    Do you get the template entity for lookup?

  • Shubh_K Profile Picture
    80 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Thanks Kokulan Eswaranathan,

    you explained very well in bits and pieces but unfortunately email template is not available to create any relationship. (community.dynamics.com/.../301649)

    Do we have any other way ?

    Thanks

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Hi

    Your requirement seems to be a Poll SMS could be sent out in multiple languages email templates and an email template could be used by multiple Polls. So we have an N:N relationship between the Poll and Email Template.

    We can use the out of the box N:N but then you won't be able to add any fields to the intermediate entity if you want to store extra info about the relationship so I would recommend you create the following

    01. First, you create all 4 email templates in different languages - Give them a consistent name

    02. Create a new entity called SMS Templates - This will have the name of the email template in the new_name field and this will also have a lookup to email template

    03. Create an intermediate entity for Poll to SMS Template N: N relationship, let's call it  Poll SMS Templates - this will have a lookup to poll and lookup to SMS template entity

    Every time when they create a poll, they just have to associate the SMS template, some polls might just go in English, some might go in all 4 or does not matter how many languages it will work

    After the above configuration, you now have a Poll record having links to SMS templates.

    Your plugin will most likely be triggering on Update of Poll i think (Send SMS Flag or something similar). In this plugin, you can query the intermediate entity to get all the SMS Template record IDs associated with that particular poll.

    Perform another query on SMS Templates entity include email lookup field in your column set and this will return all the email templates that you should be sending sms for that particular Poll

    You can then use the template Ids from the results and query the template entity to get all the template records

    You can then loop through the email template records, generate the content and then insert to contact field or use SMS services to send it.

    If you do not want to associate each poll with SMS templates and if every Poll will be sent in every language, you don't need the intermediate entity or N:N relationship.

    Just create the SMS Template entity and have the email template and create one record for each language template and set the lookup value and in your plugin just query all the active SMS language templates and loop through and send SMS.

    Hope this helps

  • Shubh_K Profile Picture
    80 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Thank you for your response dear Kokulan Eswaranathan,

    I also came across the similar approach as you suggested - Define global template, use InstantiateTemplateRequest  and capture the response with the plugin code and set as SMS Content (www.daisychubb.com/.../instantiatetemplaterequest).

    But again one problem, which is specific to my requirement that is -  For one Poll entity I have to set 4 different SMS content like English, English-Reminder, French, French-Reminder any one can be picked based on business logic, now in this way I will have to create 4 different global template and based on the condition I will have to apply any one global template.

    I explored, but I didn't find any way to associate email template with my custom entity Poll like (Poll 1 : Email Template N). What approach should I follow to allow business to associate Email template with custom entity record itself, and reduce the efforts and user friendly. I can't ask business to save Email Template  or Entity record with some unique name which I can use to identify and pick right template., how can we handle this with the plugin code ?

    Thanks

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at
    RE: How to Define SMS Template same like Email template and instantiate through code.

    Hi

    You could think about creating an email template - with all the place holders you need and then using a Custom Workflow Activity or plugin, you can generate content from template, and inserting that into a field on contact.

    If your SMS template is going to be based on custom entity, also have a look at the following tool

    archive.codeplex.com

    Even if its comes to a point you have to create an email from a template, you can copy the email body as that is your SMSs message and then get rid of the email record.

    Hope this helps

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans