locked
Plugin crm 4.0 to crm 2011 Type RRS feed

  • Question

  • Hi,

    I transform a plugin crm 4 for crm 2011.
    I get errors at particular types "Lookup", "CrmDateTime" etc.
    How to solve this problem, by which these attributes are replaced in CRM 2011?

    Wednesday, September 19, 2012 1:14 PM

Answers

  • 1. Please don't create new thread when you are asking the same or almost the same question.

    2. You should download latest SDK and recheck difference between code for 4.0 and 2011 - http://www.microsoft.com/en-us/download/details.aspx?id=24004.

    In case you are trying to fill fields of one record with fields of other record you can use following approach:

    installedproduct["field1"] = opp["field2"];

    But this will work for case when type of fields are the same.

    For lookups your code looks correct, so following snippet could be used:

    entity["field"] = new EntityReference("Referenced Entity Logical Name", <Guid of referenced record>);

    For Optionsets (Picklists) your code should look like:

    entity["field"] = new OptionSetValue(<integer code of optionset>);


    In case you want to read value of record you can use following code:

    var fieldvalue = entity.GetAttributeValue<Type>("Field Name");

    In your case it could look like:

    DateTime datetimefield = opp.GetAttributeValue<DateTime>("jx_datedevente");

    EntityReference lookupfield = opp.GetAttributeValue<EntityReference>("jx_revendeurid");

    OptionSetValue picklist = opp.GetAttributeValue<OptionSetValue>("new_marquedometic");



    Freelance Developer for Dynamics CRM 4.0/2011

    • Proposed as answer by MubasherSharif Wednesday, September 19, 2012 5:53 PM
    • Marked as answer by Jalix60 Wednesday, September 19, 2012 6:58 PM
    Wednesday, September 19, 2012 5:15 PM
    Moderator

All replies

    • Proposed as answer by _Vikram Wednesday, September 19, 2012 1:40 PM
    Wednesday, September 19, 2012 1:18 PM
    Moderator
  • Thanks but how to do with "CrmDateTimeProperty" or "PicklistProperty" etc ?

    or with attributes "Value" which not exist with "System.DateTime"

    • Edited by Jalix60 Wednesday, September 19, 2012 1:50 PM
    Wednesday, September 19, 2012 1:45 PM
  • There is no CrmDateTime anymore.

    To work with DateTime you can use standard .Net DateTime class.

    To work with picklists you should use OptionSet class.

    And there is no more properties as far as I know.

    Instead of

    entity.Properies.Add(new Property(propertyname, propertyvalue));//Pseudocode

    you can use

    entity["propertyname"] = propertyvalue;//pseudocode


    Freelance Developer for Dynamics CRM 4.0/2011

    Wednesday, September 19, 2012 1:57 PM
    Moderator
  • Yes, but if for example I want to write this line with your advice:

    installedproduct.Attributes.Add(new
    StringProperty("new_installedproductname", ((Lookup)pr["productid"]).name.ToString()));

    What is the syntax ?

    installedproduct["new_installedproductname"] = ?


    Wednesday, September 19, 2012 2:18 PM
  • Try to use following code:

    installedproduct["new_installedproductname"] = pr.FormattedValues["productid"];


    Freelance Developer for Dynamics CRM 4.0/2011

    Wednesday, September 19, 2012 2:22 PM
    Moderator
  •  ​​I can use "FormattedValues" for all types of data?
    Wednesday, September 19, 2012 2:31 PM
  • For example, this code will it work?

    installedproduct.Attributes.Add(new PicklistProperty("jx_marque", new Picklist(((Picklist)produit["new_marquedometic"]).Value)));
    
    installedproduct["jx_marque"]=produit.FormattedValues["new_marquedometic"];

    Wednesday, September 19, 2012 2:49 PM
  • Hi,

    I have a plugin crm 4.
    Someone could you point me to the code for crm 2011 please

    For DateTime

    installedproduct.Attributes.Add(new CrmDateTimeProperty("new_installationdate", ((CrmDateTime)opp["jx_datedevente"])));

    CRM 2011 : installedproduct["new_installationdate"] = (System.DateTime)opp["jx_datedevente"]; ???

    For Lookup 

    installedproduct.Attributes.Add(new LookupProperty("jx_revendeurid", new Lookup("jx_revendeur", ((Key)revendeur["jx_revendeurid"]).Value)));

    CRM 2011 : ???? installedproduct["jx_revendeurid"]= new EntityReference("jx_revendeur",new Guid (revendeur["jx_revendeurid"].ToString()));

    For Picklist :

    installedproduct.Attributes.Add(new PicklistProperty("jx_marque", new Picklist(((Picklist)produit["new_marquedometic"]).Value)));

    CRM 2011 : ??? no idea

    Wednesday, September 19, 2012 3:54 PM
  • 1. Please don't create new thread when you are asking the same or almost the same question.

    2. You should download latest SDK and recheck difference between code for 4.0 and 2011 - http://www.microsoft.com/en-us/download/details.aspx?id=24004.

    In case you are trying to fill fields of one record with fields of other record you can use following approach:

    installedproduct["field1"] = opp["field2"];

    But this will work for case when type of fields are the same.

    For lookups your code looks correct, so following snippet could be used:

    entity["field"] = new EntityReference("Referenced Entity Logical Name", <Guid of referenced record>);

    For Optionsets (Picklists) your code should look like:

    entity["field"] = new OptionSetValue(<integer code of optionset>);


    In case you want to read value of record you can use following code:

    var fieldvalue = entity.GetAttributeValue<Type>("Field Name");

    In your case it could look like:

    DateTime datetimefield = opp.GetAttributeValue<DateTime>("jx_datedevente");

    EntityReference lookupfield = opp.GetAttributeValue<EntityReference>("jx_revendeurid");

    OptionSetValue picklist = opp.GetAttributeValue<OptionSetValue>("new_marquedometic");



    Freelance Developer for Dynamics CRM 4.0/2011

    • Proposed as answer by MubasherSharif Wednesday, September 19, 2012 5:53 PM
    • Marked as answer by Jalix60 Wednesday, September 19, 2012 6:58 PM
    Wednesday, September 19, 2012 5:15 PM
    Moderator
  • I try this ... i hope it's working.

    Thank you Andrii !

    Wednesday, September 19, 2012 6:59 PM