locked
Custom entity request RRS feed

  • Question

  • I have a CRM 4 code which uses a custom entity, Punchcard, and a custom request SetStatePunchcardRequest.

    The plugin uses the old 2007 service endpoint. In my updated plugin I use the new 2011 endpoint but I cant find that request. Does anyone know where I can find those custom requests or maybe how to make my own?

     

    Thanks


    Friday, August 5, 2011 9:54 PM

Answers

  • You just need to use the SetStateRequest which is a request you can use generically with any entity:

    SetStateRequest req = new SetStateRequest
    {
        EntityMoniker = yourEntityReference,
        State = new OptionSetValue(1),
        Status = new OptionSetValue(-1)
    };
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    • Proposed as answer by Gonzalo Ruiz RModerator Friday, August 5, 2011 10:00 PM
    • Unproposed as answer by KatRiketa Friday, August 5, 2011 10:15 PM
    • Marked as answer by KatRiketa Monday, August 8, 2011 9:38 PM
    • Unmarked as answer by KatRiketa Tuesday, August 16, 2011 4:02 PM
    • Marked as answer by KatRiketa Monday, August 22, 2011 11:58 PM
    Friday, August 5, 2011 10:00 PM
    Moderator

All replies

  • You just need to use the SetStateRequest which is a request you can use generically with any entity:

    SetStateRequest req = new SetStateRequest
    {
        EntityMoniker = yourEntityReference,
        State = new OptionSetValue(1),
        Status = new OptionSetValue(-1)
    };
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    • Proposed as answer by Gonzalo Ruiz RModerator Friday, August 5, 2011 10:00 PM
    • Unproposed as answer by KatRiketa Friday, August 5, 2011 10:15 PM
    • Marked as answer by KatRiketa Monday, August 8, 2011 9:38 PM
    • Unmarked as answer by KatRiketa Tuesday, August 16, 2011 4:02 PM
    • Marked as answer by KatRiketa Monday, August 22, 2011 11:58 PM
    Friday, August 5, 2011 10:00 PM
    Moderator
  • I am using this service:

    http://{server}/{organization}/XRMServices/2011/Organization.svc

    but when I try to use SetStateRequest it says that it doesn't exist.

    Friday, August 5, 2011 10:14 PM
  • Hi

    Here is the Inheritance Hierarchy.

    System.Object
       Microsoft.Xrm.Sdk.OrganizationRequest
        Microsoft.Crm.Sdk.Messages.SetStateRequest

     

    Thanks and Regards

    Ramu

    http://www.osmosys.asia

    http://osmosee.wordpress.com

    Saturday, August 6, 2011 3:14 AM
  • If using the http://{server}/{organization}/XRMServices/2011/Organization.svc endpoint, you should reference the "microsoft.crm.sdk.proxy.dll" assembly And import the "Microsoft.Crm.Sdk.Messages" namespace.

    Then using the SetStateRequest to update the entity's status, the sample code just like Gonzalo Ruiz R writes.


    daemon lin
    Saturday, August 6, 2011 3:46 AM
  • This doesn't work for me.

    My plugin fires when the state of the Punchcard is changed. It's registered on the SetState message. Then in the plugin I change the state of the Punchcard once more. But when I do so, the plugin gets fired again by the CRM because it's state was changed, and this goes on in a loop, never reaching the end of the code. In the old code I saw that this is solved by using a custom request, SetStatePunchcard. It is used to update the state of the Punchcard in the plugin so the plugin code won't get in a loop.

    Tuesday, August 16, 2011 4:06 PM
  • There is no SetStatePunchcardRequest in CRM 2011, I understand you have a situation with an infinite loop but that is something you should consider in your design to find what is the correct way to handle the problem. If you want your plugin to change the state/status whenever the state/status is updated then why not do it in the pre-main operation and intercept the SetState request and update the input parameters instead of explicitely calling a SetStateRequest from your plugin.

    You could also store some variable in the context (SharedVariables) so that the next time your plugin gets hit, it will look for that variable and if it finds it , it can just exit to avoid an infinite loop.

    Another suggestion is that you only issue the SetStateRequest from your plugin if the current state/status is different than what you want it to be.


    Gonzalo | gonzaloruizcrm.blogspot.com

    • Marked as answer by KatRiketa Tuesday, August 16, 2011 7:12 PM
    • Unmarked as answer by KatRiketa Wednesday, August 17, 2011 11:02 PM
    Tuesday, August 16, 2011 5:51 PM
    Moderator
  • Is there I way I can make a custom request like that?

     

    Thanks

    Wednesday, August 17, 2011 6:32 PM
  • No sorry, there are no custom SDK Messages in CRM.

    Gonzalo | gonzaloruizcrm.blogspot.com

    Thursday, August 18, 2011 12:33 PM
    Moderator