在我们的应用程序中,我们创建了几千条电话记录。每个电话都应该有一个不同的所有者,由名为 GetAnyAppropriateSystemUser() 的方法确定,该方法根据某些标准找到一些随机 SystemUser。
在下面的代码示例中,我们创建了一个电话呼叫,然后在其上使用 AssignRequest 来指定其所有者。
PhoneCall phoneCall = new PhoneCall();
//
// stuff to set up the new PhoneCall instance here; populate fields, etc...
//
// determine this phonecall's owner through some algorithm
Guid appropriateOwner = GetAnyAppropriateSystemUser();
Guid createdPhoneCallId = _serviceProxy.Create(phoneCall);
if (createdPhoneCallId != Guid.Empty)
{
AssignRequest phoneCallAssign = new AssignRequest();
phoneCallAssign.Assignee = new EntityReference(SystemUser.EntityLogicalName, appropriateOwner);
phoneCallAssign.Target = new EntityReference(PhoneCall.EntityLogicalName, createdPhoneCallId);
_serviceProxy.Execute(phoneCallAssign);
}
这可以正常工作,但是有两个调用,一个要创建,一个要分配。是否可以在调用 Create() 方法之前设置 PhoneCall 记录的“ownerid”,从而消除以后调用 AssignRequest 的需要?它似乎工作,我什至在SDK中找到了一个类似的例子,如下所示。
SDK 示例:针对目标收入汇总自定义期间的目标数据
// Create three goals: one parent goal and two child goals.
Goal parentGoal = new Goal()
{
Title = "Parent Goal Example",
RollupOnlyFromChildGoals = true,
ConsiderOnlyGoalOwnersRecords = true,
TargetMoney = new Money(300.0M),
IsFiscalPeriodGoal = false,
MetricId = new EntityReference
{
Id = _metricId,
LogicalName = Metric.EntityLogicalName
},
GoalOwnerId = new EntityReference
{
Id = _salesManagerId,
LogicalName = SystemUser.EntityLogicalName
},
OwnerId = new EntityReference
{
Id = _salesManagerId,
LogicalName = SystemUser.EntityLogicalName
},
GoalStartDate = DateTime.Today.AddDays(-1),
GoalEndDate = DateTime.Today.AddDays(30)
};
_parentGoalId = _serviceProxy.Create(parentGoal);
虽然它似乎有效,但如果我们在创建新记录之前设置 ownerid,有什么我们必须注意的吗?有什么不同吗?
非常感谢您提前。