【问题标题】:How to create an email with multiple to addresses in Dynamics Online using WebApi如何使用 WebApi 在 Dynamics Online 中创建具有多个收件人地址的电子邮件
【发布时间】:2018-10-23 14:43:12
【问题描述】:

我很难弄清楚如何实例化电子邮件模板,然后使用 WebApi 创建具有多个收件人地址的电子邮件。

我遇到了很多帖子,其中一些针对旧版本的 CRM,或者他们使用 C#。本问答向您展示了这段代码工作之旅的高潮。

这些是我引用的一些帖子: Create an email activity using REST Endpoints in CRM2011-2013

Dynamics 365 Web API Email send(特别是这个答案:https://stackoverflow.com/a/47455785/44815

【问题讨论】:

    标签: dynamics-crm dynamics-crm-webapi


    【解决方案1】:
    1. 要使用电子邮件模板自动生成电子邮件内容,您需要使用“InstantiateTemplate”操作。

    该操作将如下所示的对象作为输入:

    var instantiateTemplateRequest = {
            TemplateId: templateId,
            ObjectType: objectType,
            ObjectId: objectId,
    
            getMetadata: function () {
                return {
                    boundParameter: null,
                    parameterTypes: {
                        "TemplateId": {
                            "typeName": "Edm.String",
                            "structuralProperty": 1
                        },
                        "ObjectType": {
                            "typeName": "Edm.String",
                            "structuralProperty": 1
                        },
                        "ObjectId": {
                            "typeName": "Edm.String",
                            "structuralProperty": 1
                        }
                    },
                    operationType: 0,
                    operationName: "InstantiateTemplate"
                };
            }
        };
    

    然后可以传递给:

    Xrm.WebApi.online.execute(instantiateTemplateRequest)

    返回的对象有 2 个属性:主题和描述。

    1. 从模板创建电子邮件:

    您需要使用CreateRecord method 创建电子邮件记录 它将以下类型的对象作为输入:

    var activityParties = [];
            activityParties.push({
                participationtypemask : participationTypeMasks.From,
                "partyid_queue@odata.bind" : "/queues("+ queueId+ ")"
            });
            //setup 2 send-to addresses
            activityParties.push({
                participationtypemask : participationTypeMasks.To,
                "partyid_account@odata.bind" : "/accounts(" + accountIdTo1 + ")"
            });
            activityParties.push({
                participationtypemask : participationTypeMasks.To,
                "partyid_account@odata.bind" : "/accounts(" + accountIdTo2 + ")"
            });
    
            //examples of using contacts        
            // activityParties.push({
            //     participationtypemask : participationTypeMasks.To,
            //      "partyid_contact@odata.bind" : "/contacts(00000000-0000-0000-0000-000000000000)"
            //  });
    
            //examples of using the current user as the from address
            //  var currentUserId = Xrm.Page.context.getUserId().replace("}", "").replace("{", "");
            //  activityParties.push({
            //     participationtypemask : participationTypeMasks.From,
            //      "partyid_systemuser@odata.bind" : "/systemusers("+currentUserId+")"
            //  });
    
            var email = {
                subject: emailTemplate.subject,
                description: emailTemplate.description,
                email_activity_parties: activityParties,
                "regardingobjectid_incident@odata.bind" : "/incidents(" + incidentId + ")"
            };
    

    返回的只是创建的记录的 entityId。

    我有完整的代码示例:https://github.com/rajrao/CRM-Tools/tree/master/JavaScript/CreateEmail

    【讨论】:

      猜你喜欢
      • 2021-06-07
      • 2019-07-23
      • 2021-06-27
      • 2020-12-01
      • 2017-04-03
      • 1970-01-01
      • 1970-01-01
      • 2012-05-24
      • 2011-06-04
      相关资源
      最近更新 更多