locked
update a lookup field plugin RRS feed

  • Question

  • Hi,

    I am trying to learn write plugin for updating a lookup field. Can someone give me an example or point to an article that helps me?

    Thanks

    Thursday, November 6, 2014 7:52 PM

Answers

  • hi Mate,

    http://mscrmshop.blogspot.com.au/2010/10/crm-2011-plugin-tutorial.html?m=1

    has some steps to take you to right direction. The step Polat showed should be inside the plugin.

    there is a .chm file inside CRM SDK. Contains lots of code samples. Also you can search in msdn for the same.

    let us know if you have any specific questions.

    regards

    Jithesh

    • Marked as answer by ReignFan Friday, November 7, 2014 2:04 PM
    Friday, November 7, 2014 4:24 AM
  • Hi,

    You will update your record in this statement below. It will be your lookup value. The value that you want to update to the field is that guid of entity part.

    As jithesh said this code work inside of the plugin. 

    new EntityReference("entity logical name", "guid of entity");

    Notice that if you are in post message you have to update your entity.

    service.Update(entity)
    But , ı always write this code blocks in Pre messages. So you dont need to update your entity again.


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    • Edited by Polat Aydın[MCP] Friday, November 7, 2014 10:20 AM
    • Marked as answer by ReignFan Friday, November 7, 2014 2:04 PM
    Friday, November 7, 2014 10:14 AM

All replies

  • Hi,

    You can use the code below

    if (entity.Attributes.Contains("lookup field logical name"))
    {
        entity["lookup field logical name"] = new EntityReference(	"entity logical name", "guid of entity");
    }
    else
    {
        entity.Attributes.Add("lookup field logical name", new EntityReference(	"entity logical name", "guid of entity") );
    }



    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın http://crmpolataydin.wordpress.com


    Thursday, November 6, 2014 11:37 PM
  • Is this for updating the already exisiting lookup field value?

    My apologies because I don't see where do I have to enter the update value?

    Thanks

    Friday, November 7, 2014 12:55 AM
  • hi Mate,

    http://mscrmshop.blogspot.com.au/2010/10/crm-2011-plugin-tutorial.html?m=1

    has some steps to take you to right direction. The step Polat showed should be inside the plugin.

    there is a .chm file inside CRM SDK. Contains lots of code samples. Also you can search in msdn for the same.

    let us know if you have any specific questions.

    regards

    Jithesh

    • Marked as answer by ReignFan Friday, November 7, 2014 2:04 PM
    Friday, November 7, 2014 4:24 AM
  • Hi,

    You will update your record in this statement below. It will be your lookup value. The value that you want to update to the field is that guid of entity part.

    As jithesh said this code work inside of the plugin. 

    new EntityReference("entity logical name", "guid of entity");

    Notice that if you are in post message you have to update your entity.

    service.Update(entity)
    But , ı always write this code blocks in Pre messages. So you dont need to update your entity again.


    If you find this post helpful then please Vote as Helpful and Mark As Answer. Thanks and Regards, Polat Aydın My blog


    • Edited by Polat Aydın[MCP] Friday, November 7, 2014 10:20 AM
    • Marked as answer by ReignFan Friday, November 7, 2014 2:04 PM
    Friday, November 7, 2014 10:14 AM
  • Thanks friends..

    Very informative.

    Friday, November 7, 2014 2:04 PM