How to use isAccessible() functionality in SKUID

  • 2
  • Question
  • Updated 3 years ago
  • Answered
Is there a way to access salesforce isAccessible() method in SKUID?

I have a button that needs to be displayed only for particular set of users who could have access given by  a permission set or a profile.

Thanks in-advance.
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb

Posted 3 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,004 Points 20k badge 2x thumb
Yes the "accessible" property on Model Field metadata will tell you this. You can get access to Field metadata from JavaScript via the "getField" Model API method as long as the field is in your Skuid Model. So for instance if the Contact Birthdate field is in a Skuid Model on your page called "Contact" you can do this:

var birthdateFieldIsAccessible = skuid.$M('Contact').getField('Birthdate').accessible;
(Edited)
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
Thanks, That helps Zach, I got another question, Is it possible to render a Global Action of a Table component with javascript? (I want to display the action button on the table based on the permissions of a custom object)
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,004 Points 20k badge 2x thumb
Hasantha, what I would do is this: setup a "dummy" Model, e.g. a Model on the Account object, with "Create default row if Model has none" set to true, and "Load Model data on page load" turned OFF. Add a Ui-Only field on this Model called something like "HasPermissionToUseGlobalAction", that's a Checkbox / Boolean field. Then you can Conditionally Render the Global Action based on the value of this field. THEN, use JavaScript to populate the value of this Ui-Only field on your dummy Model on initial page load, or whenever you're able to determine whether to display it or not.
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
Thanks Zach, your solution worked! :)
Photo of dibe84

dibe84

  • 212 Points 100 badge 2x thumb
Hello Zach, I'm trying your solution.. just a question: when you said "THEN, use JavaScript to populate the value of this Ui-Only field on your dummy Model on initial page load" how can I do it? I tried adding the following to the function " $(document.body).one('pageload',function() "

skuid.$M('Permission').getField('HasPermissionToPromoteScenario').Value = true;

where "Permission" is my dummy model.


but it doesnt work... If I remove the JS line and I load the page, when I inspect the attribute of "skuid.$M('Permission').getField('HasPermissionToPromoteScenario')" there is not a "Value" attribute.
Photo of dibe84

dibe84

  • 212 Points 100 badge 2x thumb
I figured it out!