OwnerId field, only give "user" option.

  • 1
  • Question
  • Updated 2 years ago
  • Answered
Is there a way to prevent the picklist that shows "user" and "group" when using the OwnerId reference field?


I would like it to not show the picklist and only show user's on the look up.
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Perfect! I actually used this earlier on a task related table and completely forgot about it. Thanks!
Photo of Hasantha Liyanage

Hasantha Liyanage

  • 1,446 Points 1k badge 2x thumb
Craig,
Could you share the solution of yours? or let me know the tweaks that we have to do here in order to get the changes applied to the ownerId field on a custom object?
Thanks
Photo of Craig Rosenbaum

Craig Rosenbaum

  • 4,776 Points 4k badge 2x thumb
Certainly. I took the solution from Zach in the above linked thread and changed the target object to 'User'. I also have a section that removes the hyperlink when the field is not in edit mode as we prefer not to link to the User object.
//
// CONFIGURATION 
// 
// Define the possible target objects 
var targetObjects = ['User']; 
// Render as a Picklist instead of an Autocomplete? 
var renderAsPicklist = false; 
var field = arguments[0], 
    value = skuid.utils.decodeHTML(arguments[1]), 
    metadata = field.metadata, 
    $ = skuid.$; 
if (field.mode == 'edit') { 
    // Limit the set of target objects 
    var targets = [], 
       uniqueTargets = {}; 
    $.each(metadata.referenceTo,function(i,r){ 
       if (($.inArray(r.objectName,targetObjects) != -1) && (!uniqueTargets[r.objectName])) { 
          targets.push(r); 
          uniqueTargets[r.objectName] = 1; 
          if (targets.length == targetObjects.length) return false; 
        } 
    }); 
    if (targets.length) { 
       // Make this field render as a picklist? 
       if (renderAsPicklist) field.options.type = 'REFPICK'; 
       // Override the current referenceTo 
       metadata.referenceTo.length = 0; 
       metadata.ref = $.map(targets,function(targ){return targ.objectName;}).join();
       metadata.referenceTo = targets; 
    } 
} 
// Run the standard renderer 
skuid.ui.fieldRenderers[metadata.displaytype][field.mode](field,value); 

//Remove the hyperlink
if (field.mode !== 'edit') {
   skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field, value);
        var linkTag = $('a', field.element);
        if(linkTag.length){
            var output = $('<div>');
            output.append(linkTag.html());
        }   
linkTag.replaceWith(output);
}