private void CreateAlternateKey(string entityName, List <string> entityFieldName, string keyDisplayName, string keyLogicalName) { EntityKeyMetadata Data = new EntityKeyMetadata(); Data.KeyAttributes = entityFieldName.ToArray(); Data.DisplayName = new Label(keyDisplayName, 1033); Data.LogicalName = keyLogicalName; Data.SchemaName = keyLogicalName; CreateEntityKeyRequest request1 = new CreateEntityKeyRequest() { EntityKey = Data, EntityName = entityName, }; IOrganizationService service = CRMHelper.ConnectToMSCRM(); CreateEntityKeyResponse response = (CreateEntityKeyResponse)service.Execute(request1); }
public void BulkUpsertRequest() { IOrganizationService service = CRMHelper.ConnectToMSCRM(); //var multipleRequest = new ExecuteMultipleRequest() //{ // // Assign settings that define execution behavior: continue on error, return responses. // Settings = new ExecuteMultipleSettings() // { // ContinueOnError = false, // ReturnResponses = true // }, // // Create an empty organization request collection. // Requests = new OrganizationRequestCollection() //}; //string accountKey = "accountnumber"; //string keyValue = string.Empty; //// First Account Record //keyValue = "123"; //Entity Account = new Entity("account", accountKey, "123"); //Account.Attributes.Add("name", keyValue); //UpsertRequest upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //// Second Account Record //keyValue = "456"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //// Third Account Record //keyValue = "789"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //// Third Account Record //keyValue = "7890"; //Account = new Entity("account", accountKey, keyValue); //Account.Attributes.Add("name", keyValue); //upReq = new UpsertRequest(); //upReq.Target = Account; //multipleRequest.Requests.Add(upReq); //ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)service.Execute(multipleRequest); EntityKeyMetadata Data = new EntityKeyMetadata(); Data.KeyAttributes = new string[] { "apttus_contactnumber" }; Data.DisplayName = new Label("Contact Number", 1033); Data.LogicalName = "apttus_contactnumber"; Data.SchemaName = "apttus_telephone1"; CreateEntityKeyRequest request1 = new CreateEntityKeyRequest() { EntityKey = Data, EntityName = "contact", }; CreateEntityKeyResponse response = (CreateEntityKeyResponse)service.Execute(request1); }