Getting attribute on related form from associated entity? RRS feed

  • Question

  • On my Contact form, I have an n:n relationship to a custom entity.  What I'm trying to do is use the Ribbon Workbench to disable the add button for the custom entity based on the value of another field on the Contact form (though I'm having trouble with this).

    So in the ribbon workbench, on the custom entity, I've added an enable rule that's a custom javascript rule.  

    Although now I seem to be having trouble accessing the parent form's attributes (because the rule is on the custom entity, but it needs to check a value on from the contact form).  I get the error " Cannot read property 'getSelectedOption' of null", so sounds like it isn't finding my contactgroup attribute. Someone suggested using parent.Xrm.  So I've tried that and window.parent.Xrm, among others.  I did google it, and there are a lot of different suggestions out there, and the ones i tried didn't work.  This is my function:

    function EnableContactGroup() {

        var CONTACTGROUP_SURVEYOR = 948140001;

        var returnValue = true;

        if (parent.Xrm.Page.getAttribute("ac_contactgroup").getSelectedOption() != null) { 

            if (parent.Xrm.Page.getAttribute("ac_contactgroup").getSelectedOption().value == CONTACTGROUP_SURVEYOR) {
                returnValue = false;

        return returnValue;

    Is there a supported way to check the value using Xrm.Page, without having to query the database?  Thanks.

    Friday, January 16, 2015 7:26 PM

All replies

  • What I should do is:

    • Open your solution with the contact entity and the custom entity in your ribbon workbench
    • Go to your custom entity (Entities Pane in Ribbon Workbench)
    • Create an Enable Rule with a Value Rule [ field=ac_contactgroup, InvertResult = True , Value = 948140001] returns false if ac_contactgroup field is 948140001
    • Customize your Add Existing button on the custom entity SubGrid.(Right click on button and customize) A Command will be added in the tree under Commands (Mscrm.Add...)
    • Add the enable rule to the added Command.

    Your Add button should now be disabled in the subgrid when you try to add a custom entity to the contact when the ac_contactgroup is not 948140001

    Hope this helps

    Kind Regards

    Monday, January 19, 2015 12:46 PM
  • Thanks, but no, that doesn't work.  I'd already tried that.  Because ac_contactgroup is not an attribute in the custom entity (that one is on the contact), it can't get the value.
    Monday, January 19, 2015 1:25 PM
  • Yes but you are adding a custom entity from the contact form (contact form is open, not custom entity form). So, ac_contactgroup should have a value. I tried it here with a yes no field and it works.
    Monday, January 19, 2015 1:29 PM
  • Hi,

    May be you better to use XrmServiceToolkit to make a query?


    Look this page.

    Monday, January 19, 2015 7:26 PM