AXForum  
Вернуться   AXForum > Microsoft Dynamics CRM > Dynamics CRM: Blogs
CRM
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 18.07.2009, 09:10   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
mscrm4ever: CRM 4.0 Setting a Picklist Default Value
Источник: http://mscrm4ever.blogspot.com/2009/...ult-value.html
==============



Currently Dynamics supports setting default values for two attribute types: PicklistAttributeMetaddata (Picklist) and BooleanAttributeMetadata (bit fields). If you intend to set the default using custom code you need to follow the below process:


1. Retrieve the attribute metadata (unless you’re creating a new one) using RetrieveAttributeRequest
2. Cast the returned AttributeMetadata to a PicklistAttributeMetadata.
3. Set the picklist metadata Default value to an integer of you choice.
4. Update the attribute metadata using UpdateAttribute Request.
5. Publish the changes using PublishXml Request.


The bellow code is a working example which sets the account Relationship Type (customertypecode) picklist to Customer (value = 3).



using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.Sdk.Metadata;
using Microsoft.Crm.SdkTypeProxy.Metadata;

namespace GI.Sendbox
{
class Program
{
static void Main(string[] args)
{
try
{
/* Create Authenticatio Token */
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = "MicrosoftCRM";

/* Create a CrmService end point */
CrmService crmService = new CrmService();
crmService.UnsafeAuthenticatedConnectionSharing = true;
crmService.Url = "http://localhost:5555/mscrmservices/2007/crmservice.asmx";
crmService.UseDefaultCredentials = true;
crmService.CrmAuthenticationTokenValue = token;

/* Create a MetadataService end point */
MetadataService metaService = new MetadataService();
metaService.Url = "http://localhost:5555/mscrmservices/2007/metadataservice.asmx";
metaService.UseDefaultCredentials = true;
metaService.UnsafeAuthenticatedConnectionSharing = true;
metaService.CrmAuthenticationTokenValue = token;

/* Retrieve the attribute metadata */
RetrieveAttributeRequest attributeRequest = new RetrieveAttributeRequest();
attributeRequest.EntityLogicalName = "account";
attributeRequest.LogicalName = "customertypecode"; //Relationship Type picklist

RetrieveAttributeResponse attributeResponse =
(RetrieveAttributeResponse)metaService.Execute(attributeRequest);

/* Cast the attribute metadata to a picklist metadata */
PicklistAttributeMetadata picklist =
(PicklistAttributeMetadata)attributeResponse.AttributeMetadata;

/* set the default value to "customer" (3) */
picklist.DefaultValue = (object)3;

/* update the attribute metadata */
UpdateAttributeRequest updateRequest = new UpdateAttributeRequest();
updateRequest.Attribute = picklist;
updateRequest.EntityName = "account";
updateRequest.MergeLabels = false;

metaService.Execute(updateRequest);

/* Publish the changes */
PublishXmlRequest request = new PublishXmlRequest();

request.ParameterXml = @"

account





";


PublishXmlResponse response =
(PublishXmlResponse)crmService.Execute(request);
}
catch(System.Web.Services.Protocols.SoapException sex)
{
Console.WriteLine(sex.Detail.OuterXml);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
}



Источник: http://mscrm4ever.blogspot.com/2009/...ult-value.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
Старый 20.07.2009, 09:44   #2  
Артем Enot Грунин is offline
Артем Enot Грунин
Moderator
Аватар для Артем Enot Грунин
MCBMSS
Злыдни
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,912 / 623 (28) +++++++
Регистрация: 16.08.2007
Адрес: Пермь!
Записей в блоге: 151
Ума не приложу, на кой черт это может понадобиться.
__________________
http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия.

MS Certified Dirty Magic Professional
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Microsoft Dynamics CRM Team Blog: Building a Self-Contained Virtual CRM Development Server Blog bot Dynamics CRM: Blogs 0 05.05.2009 10:05
Microsoft Dynamics CRM Team Blog: CRM 4.0: Checkbox style Multi-Select Picklist Blog bot Dynamics CRM: Blogs 0 01.04.2009 05:07
Microsoft Dynamics CRM Team Blog: Building Rich-Client Dashboards for Microsoft Dynamics CRM with Windows Presentation Foundation Blog bot Dynamics CRM: Blogs 1 31.03.2009 13:24
Microsoft Dynamics CRM Team Blog: List Web Part for Microsoft Dynamics CRM 4.0 Deployment Scenarios Blog bot Dynamics CRM: Blogs 0 30.01.2009 22:05
mscrm4ever: CRM 4.0 Supported Multi Select (Picklist) Control Blog bot Dynamics CRM: Blogs 0 25.12.2008 15:05

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 17:35.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.