locked
Inserting values into lookup field RRS feed

  • Question

  • I have a relationship 1:n from contact entity to custom entity called IRA. So in IRA entity i have a lookup field which i dont know how to fill in. The question is how to conect this two entities.

    Here is the code to fill up other values in IRA entity

    DynamicEntity entity = new DynamicEntity("new_ira");
                entity["new_name"] = "programski dinosaur";
                entity["new_iznos"] = new CrmDecimal(342535);
               
                Guid entityid = service.Create(entity);
    Thank you for your help
    Monday, September 28, 2009 10:19 AM

Answers

  • Hi.

    Try to use following code:

    DynamicEntity entity = new DynamicEntity("new_ira");
    entity["new_name"] = "programski dinosaur";
    entity[<name of contact lookup field>] = new Lookup("contact", <GUID of contact>);

    Guid entityid = service.Create(entity);

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Proposed as answer by D-Virdi Tuesday, September 29, 2009 6:43 AM
    • Marked as answer by bivanise Tuesday, September 29, 2009 7:47 AM
    Monday, September 28, 2009 10:22 AM
    Moderator

All replies

  • Hi.

    Try to use following code:

    DynamicEntity entity = new DynamicEntity("new_ira");
    entity["new_name"] = "programski dinosaur";
    entity[<name of contact lookup field>] = new Lookup("contact", <GUID of contact>);

    Guid entityid = service.Create(entity);

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Proposed as answer by D-Virdi Tuesday, September 29, 2009 6:43 AM
    • Marked as answer by bivanise Tuesday, September 29, 2009 7:47 AM
    Monday, September 28, 2009 10:22 AM
    Moderator
  • Hi,

    I'm a total newbie to C#.  Trying to create a custom entity record. I have created a windows service that can connect and create the CRM custom entity record  but only if I hard code the GUID's for the lookups.

    How can I pickup the GUID from the dictionary and turn it into a lookup?

     aar_assessmentresult aar_assessmentresult = new aar_assessmentresult();
     foreach (string key in dicColumnList.Keys)
                            {
                                colVal = string.Empty;
                                if (dicColumnList.TryGetValue(key, out colVal))
                                {
                                 
                                    //this works
                                    if (key.ToString() == "AssessmentResultName")
                                    {
                                        aar_assessmentresult.aar_name = colVal.Replace("'", "''");
                                    }
    
                                    //Code breaks here                               
     		if (key.ToString() == "ContactID")
                                    {
    
                                        Guid contactid = new Guid();
                                        aar_assessmentresult.aar_contactid = new Lookup();
                                        aar_assessmentresult.aar_contactid.type = "contact";
                                        aar_assessmentresult.aar_contactid.Value = contactid;
                                    }
    
                                }
                            }
         crmService.Create(aar_assessmentresult);
    
    Friday, September 23, 2011 8:15 AM