18.07.2009, 09:10 | #1 |
Участник
|
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 |
Moderator
|
Ума не приложу, на кой черт это может понадобиться.
__________________
http://fixrm.wordpress.com, снятие/наведение порчи. Быстро, дорого, гарантия. MS Certified Dirty Magic Professional |
|
|
|