locked
How can I retrieve the opportunity guid on the create? RRS feed

  • Question

  • Hi,

    I am trying to retrieve the opportunity guid(opportunityid) on the pre stage of the create.

    how can I do that?

    I have to use the pre stage because i need to update a field that that I have a update plugin on and I do not want to run the update plugin everytime on the create.

    Thanks,

    Brightlin

    Thursday, April 29, 2010 8:16 PM

Answers

  • You will have the ID in post-create, but not in Pre-Create stage, since nothing been actually persisted to database in Pre-Create. For the same reason, image wouldn't help you either. 

    Actually it does appear to me that it's CRM code, not the database, that creates ID, but you just cannot access it, and you are not supposed to access it, even if it exists. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com
    Thursday, April 29, 2010 9:29 PM

All replies

  • In Pre-Create stage, you won't have GUID available, the reason is that it has not been saved to database yet. 

    You can simply do this in Pre-Create stage, if it's a nvarchar field: 

    DynamicEntity myentity = (DynamicEntity)context.InputParameters.Properties["Target"];
    myentity.Properties["new_myfield"] = "blah blah";
    

    You don't need to make service call to make the change, new_myfield will be saved as you have provided. 

    In Post-Create stage, you can have its ID, but not in Pre-Stage. 


    Daniel Cai | http://danielcai.blogspot.com
    • Proposed as answer by ckeller Thursday, April 29, 2010 8:34 PM
    Thursday, April 29, 2010 8:24 PM
  • I'm trying to understand when the Guid is created.

    Is it only on the post-create or can I get it on the pre-create through an image?

    If CRM creates the guid I should have access before the post-create, unless it is the database the creates the guid, or the process on or after the post-create.

    Thanks,

    Brightlin

     

    Thursday, April 29, 2010 8:35 PM
  • You will have the ID in post-create, but not in Pre-Create stage, since nothing been actually persisted to database in Pre-Create. For the same reason, image wouldn't help you either. 

    Actually it does appear to me that it's CRM code, not the database, that creates ID, but you just cannot access it, and you are not supposed to access it, even if it exists. 

    Hope this helps. 


    Daniel Cai | http://danielcai.blogspot.com
    Thursday, April 29, 2010 9:29 PM