How can I create a lookup field to the userRole object

  • 1
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
Since I know this can't be done since this object doesn't allow for it, I'd like to fake this functionality in Skuid. I can create a text field called Role. I can create a custom field renderer. I can store the Role ID in the text field and render it's Name in read mode and render a picklist in edit mode.

The question is how as I'm still rather novice when it comes to custom field renderers.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I've gotten this far, but some pointers would be appreciated. Please don't give me the solution though. Going to the "else" bit now as I know how to do this part.

var field = arguments[0],
    value = skuid.utils.decodeHTML(arguments[1]),
    userRoleModel = skuid.$M('UserRoles');
    

if (field.mode == 'edit') {

        // lookup values in userRole in order to display then in a picklist


} else {
        
        // find the Name of the userRole based on the value in the text field called Role and display name
}
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Halfway there. :D





var field = arguments[0],
    value = skuid.utils.decodeHTML(arguments[1]),
    $ = skuid.$,
    dfd = new jQuery.Deferred(),
    userRoleModel = skuid.$M('UserRoles'),
    currentUserRoleModel = skuid.$M('CurrentUserRole'),
    currentUserRoleModelCond = currentUserRoleModel.getConditionByName('roleId');
    

if (field.mode == 'edit') {

        // lookup values in userRole in order to display then in a picklist


} else {
        
        // find the Name of the userRole based on the value in the text field called Role and display name
        currentUserRoleModel.setCondition(currentUserRoleModelCond,value);
        $.when(currentUserRoleModel.updateData())
            .done(function(){
                var currentURMRow = currentUserRoleModel.getFirstRow();
                // set the value of the field
                skuid.ui.fieldRenderers.TEXT.read( field, currentURMRow.Name );
                
                dfd.resolve();
            })
            .fail(function(){
                dfd.reject();
            });
}

return dfd.promise();
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I think I got it.
  1. Create an array called userRolePicklist
  2. Loop through the rows in the userRole model
  3. Create an object for each row and push it into the array userRolePicklist
  4. update field.metadata.picklistEntries with userRolePicklist
Moshe, Barry, Irvin, anyone from Skuid dev? Right track?
(Edited)
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
AWESOME!!!! A text field that acts like a lookup field to an object that doesn't allow lookups to it!!! 

(Edited)
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Pat...this thread makes me smile. Four posts of you answering your own question. :)
(Edited)
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
hehehehe... I wasn't willing to wait for the answer. ;)
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Talking about arrays and objects like a real pro, no more javascript rookie!
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
Getting there. Slow but sure.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Well done Pat..