开发者

How to set a specific picklist value on crm 4.0?

i try to set selected value of my picklist while adding a new account.My code is :

        CrmService service = connectToCrm();
        PropertyCollection Prop = new PropertyCollection();
        DynamicEntity Firma = new DynamicEntity();

        // set table
        Firma.Name = EntityName.account.ToString();

        StringProperty accountName = new StringProperty();
        accountName.Name = "name";
        accountName.Value = aDict["name"].ToString();
        Prop.Add(accountName);

        StringProperty vendorCode = new StringProperty();
        vendorCode.Name = "new_bayikodu";
        vendorCode.Value = aDict["new_bayikodu"].ToString();
        Prop.Add(vendorCode);

        StringProperty VD = new StringProperty();
        VD.Name = "new_taxoffice";
        VD.Value = aDict["new_taxoffice"].ToString();
        Prop.Add(VD);

        StringProper开发者_Go百科ty VN  = new StringProperty();
        VN.Name = "accountnumber";
        VN.Value = aDict["accountnumber"].ToString();
        Prop.Add(VN);

        StringProperty address = new StringProperty();
        address.Name = "address1_line1";
        address.Value = aDict["address1_line1"].ToString();
        Prop.Add(address);

        StringProperty tel = new StringProperty();
        tel.Name = "telephone1";
        tel.Value = aDict["telephone1"].ToString();
        Prop.Add(tel);

        StringProperty accountEmail = new StringProperty();
        accountEmail.Name = "emailaddress1";
        accountEmail.Value = aDict["emailaddress1"].ToString();
        Prop.Add(accountEmail);

        Firma.Properties = Prop;       

        Guid CustomerGuid = service.Create(Firma);

Example i want to set city picklist to "istanbul" can i use a picklistproperty ?


Here is a similar question asked in SO: Setting BusinessEntity picklist value using CRM 4.0 webservice

Please note that to set a picklist property on an entity, you need to know the value of the picklist item you wish to choose. This value property is of type integer. You may need to look at the attribute schema from within CRM to get this value. Or alternatively if this customization is going to be installed in multiple organizations and you believe this value might change, then you may need to retrieve the attribute metadata and determine the correct item programmatically based on the name. (This 2nd solution is not ideal as the picklist 'name' could be updated and would therefore break your code).

    PicklistProperty city = new PicklistProperty();
    city.Name = "new_city";
    city.Value = 23; // City Picklist Value for 'istanbul';
    Prop.Add(city);


PicklistProperty city = new PicklistProperty();
city.Name = "new_city";
city.Value = new Picklist();
city.Value.Value = 23; // City Picklist Value for 'istanbul';

Then you can use 'city' to set your picklist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜