我得到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问题”,已经创建了一个用户,但仍然出现错误。
答案 0 :(得分:0)
一步一步走。您拥有三件事,例如创建用户,检索FullName列,然后更新clinic.new_ClinicCoordinator
字段。注释掉这两个步骤,并验证是否正在创建用户,如果创建成功,然后再检索(因为您已经具有更新所需的systemID,所以不需要此操作)
使用try catch更好地处理代码中的异常
编辑:CRM在线互动用户无法用代码创建。 Read more
更新:
合并以下各行,因为ser_contract
对象不会使用创建的Guid重新更新。对hospitalID
也要这样做。
Service().Create(ser_contract);
Guid ser_con_id = (Guid)ser_contract.Id;
这应该有效:
Guid ser_con_id = Service().Create(ser_contract);