使用 QueryExpression 获取机会 (Opty) id 和机会名称
Getting Opportunity (Opty) id and Opportunity name using QueryExpression
我正在使用 Dynamics CRM 365。我使用 queryexpression 检索 Opty 名称和 Opty id(唯一)。
QueryExpression queryOnline = new QueryExpression("opportunity");
queryOnline.Criteria = new FilterExpression();
queryOnline.Criteria.AddCondition("createdon", ConditionOperator.LastXDays, hours);
queryOnline.Criteria.AddCondition("statuscode", ConditionOperator.Equal, 1); // For Open Opportunity
queryOnline.ColumnSet = new ColumnSet(true);
EntityCollection entCol = _service.RetrieveMultiple(queryOnline);
foreach (Entity presName in entCol.Entities)
{
//Get Opty ID and Name
}
现在我想创建 SendEmailRequest
来发送我使用上述方法检索的机会记录。简而言之,我想用以下格式创建 SendEmailRequest
:
在电子邮件描述中(多行文本/字符串):
You have open opportunities:
ID || NAME
00001 || OPEN OPTY NAME
00002 || OPEN OPTY NAME
我已成功创建发送电子邮件请求,无论是否使用模板。但是当我想将查询表达式中的可选记录粘贴到电子邮件描述中时,我遇到了问题。电子邮件描述是字符串格式的 "multiple lines of text" 字段。
电子邮件描述字段接受 HTML 格式,您应该创建一个 HTML 电子邮件正文并将其传递给描述。对于机会值,将您的 ColumnSet 更改为:
queryOnline.ColumnSet = new ColumnSet("name", "opportunityid");
然后,您的 foreach 可能看起来像这样:
string htmlDescription = "<ul>";
foreach (Entity presName in entCol.Entities)
{
//Get Opty ID and Name
htmlDescription += string.Format("<li>{0} || {1}</li>", presName.Id, presName.GetAttributeValue<string>("name"));
}
htmlDescription += "</ul>";
当然只是一个基本示例。
我正在使用 Dynamics CRM 365。我使用 queryexpression 检索 Opty 名称和 Opty id(唯一)。
QueryExpression queryOnline = new QueryExpression("opportunity");
queryOnline.Criteria = new FilterExpression();
queryOnline.Criteria.AddCondition("createdon", ConditionOperator.LastXDays, hours);
queryOnline.Criteria.AddCondition("statuscode", ConditionOperator.Equal, 1); // For Open Opportunity
queryOnline.ColumnSet = new ColumnSet(true);
EntityCollection entCol = _service.RetrieveMultiple(queryOnline);
foreach (Entity presName in entCol.Entities)
{
//Get Opty ID and Name
}
现在我想创建 SendEmailRequest
来发送我使用上述方法检索的机会记录。简而言之,我想用以下格式创建 SendEmailRequest
:
在电子邮件描述中(多行文本/字符串):
You have open opportunities:
ID || NAME
00001 || OPEN OPTY NAME
00002 || OPEN OPTY NAME
我已成功创建发送电子邮件请求,无论是否使用模板。但是当我想将查询表达式中的可选记录粘贴到电子邮件描述中时,我遇到了问题。电子邮件描述是字符串格式的 "multiple lines of text" 字段。
电子邮件描述字段接受 HTML 格式,您应该创建一个 HTML 电子邮件正文并将其传递给描述。对于机会值,将您的 ColumnSet 更改为:
queryOnline.ColumnSet = new ColumnSet("name", "opportunityid");
然后,您的 foreach 可能看起来像这样:
string htmlDescription = "<ul>";
foreach (Entity presName in entCol.Entities)
{
//Get Opty ID and Name
htmlDescription += string.Format("<li>{0} || {1}</li>", presName.Id, presName.GetAttributeValue<string>("name"));
}
htmlDescription += "</ul>";
当然只是一个基本示例。