How can I create a lookup field to the userRole object

Pat VachonPat Vachon Member ✭✭
edited June 25 in Questions
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.

Comments

  • Pat VachonPat Vachon Member ✭✭
    edited June 25
    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  }
  • Pat VachonPat Vachon Member ✭✭
    edited January 2016
    Halfway there. :D

    image

    image
    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();
  • Pat VachonPat Vachon Member ✭✭
    edited June 25
    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?
  • Pat VachonPat Vachon Member ✭✭
    edited June 25
    AWESOME!!!! A text field that acts like a lookup field to an object that doesn't allow lookups to it!!! 





  • Matt SonesMatt Sones Member ✭✭
    edited June 25
    Pat...this thread makes me smile. Four posts of you answering your own question. :)
  • Pat VachonPat Vachon Member ✭✭
    edited January 2016
    hehehehe... I wasn't willing to wait for the answer. ;)
  • Moshe KarmelMoshe Karmel Member
    edited June 25
    Talking about arrays and objects like a real pro, no more javascript rookie!
  • Pat VachonPat Vachon Member ✭✭
    edited January 2016
    Getting there. Slow but sure.
  • Rob HatchRob Hatch Skuad, Sonar ✭✭
    edited September 2016
    Well done Pat.. 
Sign In or Register to comment.