locked
get current record id using plugin RRS feed

  • Question

  • Hi all,

    I need to get current record id using a plugin in CRM 4 to be used in query condition, please advise

     

    thanks in advance..


    Monday, June 20, 2011 1:17 PM

Answers

  • Guid entityid = Guid.Empty;

    if (context.MessageName == MessageName.Create)

    {

    entityid = (Guid)context.OutputParameters[ParameterName.Id];

    }

    else if (context.MessageName == MessageName.Update)

    {

    DynamicEntity entity = context.InputParameters[ParameterName.Target] as DynamicEntity;

    string keyfieldname = string.Format("{0}id", entity.Name);

    if (entity.Properties.Contains("activityid"))

    keyfieldname = "activityid";

    entityid = ((Key)entity[keyfieldname]).Value;

    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Monday, June 20, 2011 2:12 PM
    Moderator

All replies

  • Hello Mostafa,

     

    Please check out the following article: http://asadewa.wordpress.com/2008/05/21/crm-40-plug-in-getting-entity-id-is-it-just-me-or/.


    Cornel Croitoriu - Senior Software Developer & Entrepreneur

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Biz-Forward.comCroitoriu.NET

    Monday, June 20, 2011 1:37 PM
  • Dear Cornel,

     

    not working...

     

    thanks alot for your efforts

    Monday, June 20, 2011 1:51 PM
  • Guid entityid = Guid.Empty;

    if (context.MessageName == MessageName.Create)

    {

    entityid = (Guid)context.OutputParameters[ParameterName.Id];

    }

    else if (context.MessageName == MessageName.Update)

    {

    DynamicEntity entity = context.InputParameters[ParameterName.Target] as DynamicEntity;

    string keyfieldname = string.Format("{0}id", entity.Name);

    if (entity.Properties.Contains("activityid"))

    keyfieldname = "activityid";

    entityid = ((Key)entity[keyfieldname]).Value;

    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Monday, June 20, 2011 2:12 PM
    Moderator
  • Dear Andriy,

     

    thanks alot, you are really helpful, but I have a question for you, is it necessary to update a record using its ID ?? I mean is there anyway to update records based on another criteria ?

    thanks in advance..

    Monday, June 20, 2011 3:03 PM
  • No other way I'm afraid.
    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Monday, June 20, 2011 3:06 PM
    Moderator
  • Dear Andriy,

     

    What about doing this on CRM 2011 ??

    Monday, June 20, 2011 3:07 PM
  • Dear Andriy,

     

    What about doing this on CRM 2011 ??

    4.0/2011 - doesn't matter. If you don't believe me - you should check SDK. All the required information can be found there.

    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Monday, June 20, 2011 3:13 PM
    Moderator
  • Dear Andriy,

     

    It doesn't mean that I don't believe you, I was checking if there exist a way to do it on the new version accordingly may be I will postpone my requirements till upgrade

    Monday, June 20, 2011 3:16 PM
  • So here is the dilemma,

     

    I need to update a set of records where a lookup field is filled with a specific value, could you please guide me through this requirements ??

    I don't need a ready made code, or that you the job for me I just need another mind to think

     

    thanks in advance..

    Monday, June 20, 2011 3:21 PM