/// <summary> /// 옵션집합 가져오기 /// </summary> /// <param name="optionSetName"></param> /// <returns></returns> public DtoOptionSet RetrieveGlobalOptionSet(string optionSetName) { try { RetrieveOptionSetRequest retrieveOptionSetRequest = new RetrieveOptionSetRequest { Name = optionSetName }; // Execute the request. RetrieveOptionSetResponse retrieveOptionSetResponse = (RetrieveOptionSetResponse)_orgService.Execute(retrieveOptionSetRequest); //Console.WriteLine("Retrieved {0}.", retrieveOptionSetRequest.Name); // Access the retrieved OptionSetMetadata. OptionSetMetadata retrievedOptionSetMetadata = (OptionSetMetadata)retrieveOptionSetResponse.OptionSetMetadata; DtoOptionSet retVal = new DtoOptionSet { SchemaName = optionSetName, DisplayName = retrievedOptionSetMetadata.DisplayName.UserLocalizedLabel.Label, Description = retrievedOptionSetMetadata.Description.UserLocalizedLabel.Label }; return(retVal); } catch (Exception) { throw; } }
/// <summary> /// Global OptionSet 생성 /// </summary> /// <param name="dto"></param> public void CreateGlobalOptionSet(DtoOptionSet dto) { try { OptionSetMetadata setupOptionSetMetadata = GetSetupOptionSetMetadata(dto); // Wrap the OptionSetMetadata in the appropriate request. CreateOptionSetRequest createOptionSetRequest = new CreateOptionSetRequest { SolutionUniqueName = !string.IsNullOrEmpty(_solutionName) ? _solutionName : null, OptionSet = setupOptionSetMetadata }; // Pass the execute statement to the CRM service. OrganizationResponse responseFromUpdateOptionSet = _orgService.Execute(createOptionSetRequest); //foreach (var r in response.Results) //{ // Console.WriteLine(r.Value.ToString()); //} OrganizationResponse responseFromOptions = InsertOrUpdateForOptionSetOptions(dto); } catch (Exception) { throw; } }
/// <summary> /// Global OptionSet 세팅 값 가져오기 /// </summary> /// <param name="dto"></param> /// <returns></returns> private OptionSetMetadata GetSetupOptionSetMetadata(DtoOptionSet dto) { OptionSetMetadata setupOptionSetMetadata = new OptionSetMetadata() { Name = dto.SchemaName, DisplayName = new Label(dto.DisplayName, _languageCode), Description = new Label(dto.Description ?? string.Empty, _languageCode), IsGlobal = true, OptionSetType = OptionSetType.Picklist, }; return(setupOptionSetMetadata); }
/// <summary> /// Global OptionSet의 Options 값을 Insert or Update /// </summary> /// <param name="dto"></param> /// <returns></returns> private OrganizationResponse InsertOrUpdateForOptionSetOptions(DtoOptionSet dto) { try { OrganizationResponse response = null; OptionMetadata[] options = RetrieveGlobalOptionSetOptions(dto.SchemaName); // Add a label and value to Global OptionSet foreach (var o in dto.Options) { var optionCnt = options.Where(a => a.Value == o.Value).Count(); if (optionCnt == 0) { InsertOptionValueRequest insertOptionValueRequest = new InsertOptionValueRequest { OptionSetName = dto.SchemaName, Value = o.Value, // optional value - if ommited one will get assigned automatically Label = new Label(o.Label, _languageCode), Description = new Label(o.Description ?? string.Empty, _languageCode) }; response = _orgService.Execute(insertOptionValueRequest); // int retVal = ((InsertOptionValueResponse)_orgService.Execute(insertOptionValueRequest)).NewOptionValue; } else // (optionCnt > 0) { UpdateOptionValueRequest updateOptionValueRequest = new UpdateOptionValueRequest { OptionSetName = dto.SchemaName, Value = o.Value, // optional value - if ommited one will get assigned automatically Label = new Label(o.Label, _languageCode), Description = new Label(o.Description ?? string.Empty, _languageCode) }; response = _orgService.Execute(updateOptionValueRequest); } } return(response); } catch (Exception) { throw; } }
/// <summary> /// Global OptionSet 업데이트 /// </summary> /// <param name="dto"></param> public void UpdateGlobalOptionSet(DtoOptionSet dto) { try { OptionSetMetadata setupOptionSetMetadata = GetSetupOptionSetMetadata(dto); // Wrap the OptionSetMetadata in the appropriate request. UpdateOptionSetRequest updateOptionSetRequest = new UpdateOptionSetRequest { OptionSet = setupOptionSetMetadata }; // Pass the execute statement to the CRM service. OrganizationResponse responseFromUpdateOptionSet = _orgService.Execute(updateOptionSetRequest); OrganizationResponse responseFromOptions = InsertOrUpdateForOptionSetOptions(dto); } catch (Exception) { throw; } }