locked
Automatically Associate Resource with Resource Group RRS feed

  • Question

  • Hi guys, I have a simple requirement which has turned out to be rather difficult to implement.

    On create of a Facility/Equipment record, I want to automatically add them into a specific Resource Group which already exists.

    I expected this to be a simple plugin on create of Facility/Equipment which SDK Associate Request to link the two records together, however I don't see any relationship between Facility/Equipment and Resource Group.

    I've check through customizations as well as through SQL and cannot see how this is done.

    I'm assuming this is some sort of hidden complex relationship since Resource Groups can contain more than just Facility/Equipment, so wondering if there's any way to do this?

    Thanks

    Monday, April 20, 2015 5:00 AM

Answers

  • This article will help you:-

    https://social.microsoft.com/Forums/en-US/2ff892db-d706-4ad7-b73b-2123585a3c92/programmatically-add-resource-to-resource-group?forum=crmdevelopment


    Regards Faisal

    • Marked as answer by crmdude1 Monday, April 20, 2015 10:28 PM
    Monday, April 20, 2015 10:40 AM
  • Thanks guys, the catch here is that the resources are for some reason stored in the 'Constraints' field on the resource group instead of an actual relationship (WHY CRM!!)

    So instead of doing an associate request we need to get the existing constraints on the resource group, extract the XML, and then rebuild it to include our new resource.

    The link you posted Faisal shows how this works. Basically the constraints look like this:

    <Constraints><Constraint><Expression><Body>resource[\"Id\"] == {789ce16b-1319-e411-80b7-00155d048d13} || resource[\"Id\"] == {419b4e1d-a0e7-e411-80be-00155d048d13}</Body><Parameters><Parameter name=\"resource\" /></Parameters></Expression></Constraint></Constraints>

    Where the contents of the <Body> tag contain each of the resources associated with the resource group.

    Now it's just a matter of "simply" adding another resource into that body and then updating the resource group.

    Thanks again guys.

    • Marked as answer by crmdude1 Monday, April 20, 2015 10:33 PM
    Monday, April 20, 2015 10:33 PM

All replies

  • This can be done, but you have to dig into the details of the ResourceSpec and ConstraintBasedGroup entities. The best place to start is to check what the data in these entities looks like when you manually add an equipment record to a ResourceGroup, and mimic that in the plugin

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Monday, April 20, 2015 7:11 AM
    Moderator
  • This article will help you:-

    https://social.microsoft.com/Forums/en-US/2ff892db-d706-4ad7-b73b-2123585a3c92/programmatically-add-resource-to-resource-group?forum=crmdevelopment


    Regards Faisal

    • Marked as answer by crmdude1 Monday, April 20, 2015 10:28 PM
    Monday, April 20, 2015 10:40 AM
  • Thanks guys, the catch here is that the resources are for some reason stored in the 'Constraints' field on the resource group instead of an actual relationship (WHY CRM!!)

    So instead of doing an associate request we need to get the existing constraints on the resource group, extract the XML, and then rebuild it to include our new resource.

    The link you posted Faisal shows how this works. Basically the constraints look like this:

    <Constraints><Constraint><Expression><Body>resource[\"Id\"] == {789ce16b-1319-e411-80b7-00155d048d13} || resource[\"Id\"] == {419b4e1d-a0e7-e411-80be-00155d048d13}</Body><Parameters><Parameter name=\"resource\" /></Parameters></Expression></Constraint></Constraints>

    Where the contents of the <Body> tag contain each of the resources associated with the resource group.

    Now it's just a matter of "simply" adding another resource into that body and then updating the resource group.

    Thanks again guys.

    • Marked as answer by crmdude1 Monday, April 20, 2015 10:33 PM
    Monday, April 20, 2015 10:33 PM