-
要使用电子邮件模板自动生成电子邮件内容,需要使用“
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(实例化模板请求)
返回的对象有两个属性:主题和说明。
-
要从模板创建电子邮件:
您需要使用创建电子邮件记录
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