我看过通过 C# 创建客户实体记录、联系人实体记录的示例,我想知道我们如何通过 C#(.net) 代码在 CRM 中创建服务记录。
例如:我们在服务实体 View 中已经有了“管道服务”记录。所以我想通过 C# 代码在服务实体中创建一条新记录(早绑定(bind)或晚绑定(bind)无关紧要)。
谁能用代码帮我解决这个问题。
最佳答案
从代码创建此服务时需要相当多的 XML。此外,在创建服务之前,您需要创建 ResourceSpec 和 ConstraintBasedGroup。
首先创建一个ConstraintBasedGroup:
var bu = context.BusinessUnitSet.First().ToEntityReference();
var cbg = new ConstraintBasedGroup
{
BusinessUnitId = bu,
Name = "CBG1",
Constraints = "<Constraints><Constraint><Expression><Body>false</Body><Parameters><Parameter name=\"resource\"/></Parameters></Expression></Constraint></Constraints>"
};
var cbgId = OrganizationService.Create(cbg);
然后创建一个 ResourceSpec:
var resSpec = new ResourceSpec
{
BusinessUnitId = bu,
Name = "RS1",
RequiredCount = 1,
ObjectiveExpression = "<Expression><Body>udf\"Random\"(factory,resource,appointment,request,leftoffset,rightoffset)</Body><Parameters><Parameter name=\"factory\"/><Parameter name=\"resource\"/><Parameter name=\"appointment\"/><Parameter name=\"request\"/><Parameter name=\"leftoffset\"/><Parameter name=\"rightoffset\"/></Parameters><Properties EvaluationInterval=\"P0D\" evaluationcost=\"0\"/></Expression>",
GroupObjectId = cbgId
};
var resSpecId = OrganizationService.Create(resSpec);
最后,您可以创建自己的服务:
var svc = new Service
{
Name = "Service1",
Granularity = "FREQ=MINUTELY;INTERVAL=15",
ResourceSpecId = new EntityReference(ResourceSpec.EntityLogicalName, resSpecId),
InitialStatusCode = new OptionSetValue(0),
Duration = 15
};
OrganizationService.Create(svc);
我建议您使用 CRM 的 UI 创建类似的东西,以防您对所需 XML 的特定格式感到疑惑。我在示例中使用的 XML 几乎是 CRM 生成的默认 XML。
关于c# - 在服务实体中创建新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36352224/