Modify read/edit by role

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I'd like to find a way to make a few fields read only based on a users role. I've created a model that contains this information via the User object but I'm unsure how to access this information through javascript. 
Photo of John Harris

John Harris

  • 254 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Photo of Joe Ort

Joe Ort

  • 2,256 Points 2k badge 2x thumb
Can you limit editing rights based on the Field Level Security for that role?  Standard SFDC functionality vs javascript?
Photo of John Harris

John Harris

  • 254 Points 250 badge 2x thumb
Thanks, guys. I was able to do so via bastardized code below. I created a model called 'Running User' and pulled in role. After creating this snippet I modified the 'Field Renderer' field property to 
'Custom run a Snippet' and input the snippet name. 

var m = skuid.model.getModel('RunningUser');
var row = m.getFirstRow(); 
var fieldToCheck = row.UserRole.Name; 

var field   = arguments[0],
$       = skuid.$,
    value   = arguments[1]; 


// Set the value to be read only if the role is 'Child'
if (fieldToCheck == 'Child') {
    field.mode = 'readonly'; 
    
    var renderers = skuid.ui.fieldRenderers; 
    var dt = field.metadata.displaytype; 
    var r = renderers[dt]; 
    
    if (!r) r = renderers.PICKLIST; 
    r.readonly(field,value);
} else {
    skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field, value);
}
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Glad you got it working.

Unless I'm mistaken, skuid respects your SFDC field level security.
Photo of Joe Ort

Joe Ort

  • 2,256 Points 2k badge 2x thumb
You're right, Matt.
Photo of John Harris

John Harris

  • 254 Points 250 badge 2x thumb
The only issue with FLS in this scenario is it's based on profiles or users (via permission sets) not roles.