【发布时间】:2018-07-28 19:04:51
【问题描述】:
我收到error - no service provision,请有经验的人帮助我。
var clinic = new new_clinic();
clinic.new_name = "Medinet";
Account trust = new Account();
trust.Name = "bIRMINGHAM CITY hOSPITAL";
Guid trustID = (Guid)Service().Create(trust);
CrmEntityReference clinic_trust = new CrmEntityReference(trust.LogicalName, trustID);
clinic.new_Trust = clinic_trust;
clinic.new_ClinicDate = DateTime.Now;
new_hospital hospital = new new_hospital();
hospital.new_name = "Geek-guru";
Service().Create(hospital);
Guid hospitalID = (Guid)hospital.Id;
clinic.new_HostingHospital = new CrmEntityReference(hospital.LogicalName, hospitalID);
clinic.new_ClinicDate = new DateTime(2018, 07, 28);
new_serviceprovision ser_contract = new new_serviceprovision();
ser_contract.new_Trust = clinic_trust;
ser_contract.new_Specialty = new OptionSetValue(100000018);
Service().Create(ser_contract);
Guid ser_con_id = (Guid)ser_contract.Id;
clinic.new_ServiceContract = new CrmEntityReference(ser_contract.LogicalName, ser_con_id);
// Account account = (Account)GetOrgService().Retrieve(trust.LogicalName, trustID, new Microsoft.Xrm.Sdk.Query.ColumnSet("name"));
//retreive the default business unit needed to create the user
QueryExpression businessUnitQuery = new QueryExpression
{
EntityName = BusinessUnit.EntityLogicalName,
ColumnSet = new ColumnSet("businessunitid"),
Criteria = { Conditions = { new ConditionExpression("parentbusinessunitid", ConditionOperator.Null) } }
};
BusinessUnit businessUnit = Service().RetrieveMultiple(businessUnitQuery).Entities[0].ToEntity<BusinessUnit>();
//creating a user
SystemUser systemUser = new SystemUser();
systemUser.DomainName = "" + "Chika";
systemUser.FirstName = "Olabajo";
systemUser.LastName = "Boss";
systemUser.InternalEMailAddress = "onyebuchi@gmail.com";
systemUser.BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, businessUnit.Id);
Guid systemID = (Guid)Service().Create(systemUser);
// systemUser = (SystemUser)Service().Retrieve(systemUser.LogicalName, systemID, new Microsoft.Xrm.Sdk.Query.ColumnSet("fullname"));
//this field is a lookup field to User. Assigned to the user created above
clinic.new_ClinicCoordinator = new CrmEntityReference(systemUser.LogicalName, systemID);
clinic.new_BookedBy = new OptionSetValue(100000001);
clinic.new_Type1 = new OptionSetValue(100000008);
clinic.new_Type2 = new OptionSetValue(100000001);
clinic.new_NumberofConsultants = 5;
clinic.new_NumberofNursesSuppliedByTrust = 6;
Service().Create(clinic);//getting error here
MessageBox.Show("Sucessfully added a clinic record");
我已经在这些方面工作了好几个星期了,我希望能得到一点帮助。 我现在遇到“没有 serviceprivison 问题”,现在已经创建了一个用户,但仍然出现错误。
【问题讨论】:
-
这段代码在哪里运行,控制台应用程序或插件?把try catch?你调试了吗?您标记了 2011 和在线 - 是否在线,那么您无法创建这样的用户。
-
windows窗体运行,使用早期绑定类,动态CRM上线。
-
@ArunVinoth hi Arun,感谢您的响应,但它没有被创建,因为 id 只是零。
-
@ArunVinoth 看到这里,它是在 sdk 中完成的,我做了同样的事情,但得到一个错误。 msdn.microsoft.com/en-us/library/jj602984.aspx
-
这是本地非在线的代码示例;另请注意,您没有在请求中传递域名和业务单位值,这是强制性的。
标签: c# dynamics-crm dynamics-crm-2011 entity-relationship