1

I am trying to hide or show a button based on if the user belongs to a particular team or not. I am doing this via a JavaScript function that returns either true or false.

This is working in all scenarios apart from when the button appears on a view of the entity. In this case the JavaScript never seems to run. However if the default for the custom rule is set to True then the button shows but if set to False it doesn't show. So it seems it is seeing the default of the Enable rule but not running the JavaScript in this instance.

Am I missing something here?

As requested here is the function, as I previously posted this function is working correctly in other contexts.

function allowedNewButton() {
    if (UserHasTeam("Create Order")) {
        return true;
    } else {
        return false;
    }
}

enter image description here

Jon Farmer
  • 326
  • 1
  • 6
  • 16
  • Lame Question, Did you set your Enable rule on Home (i.e View). Probably you set it only on From level. – AnkUser Apr 29 '19 at 11:47
  • Yes the Enable rule is on Home – Jon Farmer Apr 29 '19 at 11:50
  • ok, 1.Probably Script is not loaded. 2.Is java script calling any Async operation? For Ribbion workbench, isNaN is no more needed on Version 9, But if you are not on Version 9 Try adding Javascript (i.e Loading it first) with isNaN. Also if you could post screenshot for your Enable rule and add your code to question Link for Ref: https://community.dynamics.com/crm/b/develop1/archive/2017/11/27/ribbon-dependencies-in-version-9-isnan-is-no-more – AnkUser Apr 29 '19 at 11:57
  • Is the call to Webapi/Odata Async? Are you on Ribbon Workbench Version 9? If not IsNaN?? Deleting and recreating Enable Rule agin? – AnkUser Apr 29 '19 at 13:05
  • 1
    Looking at the Javascript console I can now see the JavaScript is running but the Enable rule seems to be ignoring the return result from the function. – Jon Farmer Apr 29 '19 at 13:24
  • Using the debugger I can see this line in the UserHasTeam() function seems to be killing the process 'var service = GetRequestObject();' – Jon Farmer Apr 29 '19 at 13:42
  • 1
    Could you post your code for function UserHasTeam("Create Order") – AnkUser Apr 29 '19 at 14:20

0 Answers0