How to use "Name" value (FullName) from User List rather than "Value" (Email Address)?

Comments

7 comments

  • Avatar
    Loren Bratzler

    Since the User List is essentially a drop-down Name/Value field, only the value is going to be available in your schema.  To do what you want to do, you will need to define an additional hidden text-box field on your form to contain the Full Name.  Then you will need to create a little JavaScript code to pull the selected Name from the drop-down and populate your hidden Full Name field.

    So let's say you define a hidden text-box called SystemOwnerName.  You will then need to add the following JavaScript to your form:

    function getSystemOwnerName()
    {
      var dropDownSelectName = dropdownDisplayValue("systemowner5");
      setFieldNameObjectValue("SystemOwnerName",dropDownSelectName);
    }

    function dropdownDisplayValue(dropdownFieldName)
    {
      var dropDownSelectObj = getFieldNameObject(dropdownFieldName);
      var dropDownSelect = dropDownSelectObj.find("option:selected").text();
      return dropDownSelect;
    }

    function getFieldNameObject(fieldName)
    {
      var fieldObj;
      eFormHelper.getField({ fieldId: fieldName }, function (result) { fieldObj = result.data; });
      return fieldObj;
    }

    function setFieldNameObjectValue(fieldName, val)
    {
      eFormHelper.setFieldValue({ fieldId: fieldName, value: val });
    }

     

    Then on your User-List control, go to the Advanced tab and tell it that you want to execute the JavaScript function getSystemOwnerName() on the "Change" event:

    This will then populate the SystemOwnerName field with the Full Name selected from the User-List.  You can then use the SystemOwnerName field in your email.

    The JavaScript I displayed above could probably be condensed by combining some of the functions.  I just copied this from an existing application I have where I call those various functions for different reasons.

    0
    Comment actions Permalink
  • Avatar
    Sampat Patil

    Hi Valerie,

    The solution provided by Loren is right way (Script + User list control change event).

    Also, I have same solution with script only approach (Below scripts are self-explanatory and easy to maintain )

    /* Helper methods - (below 2 methods never changes) */
    function Set(name, value) { eFormHelper.setFieldValue({fieldId: name, value: value}); }
    function GetControl(name) { var r; eFormHelper.getField({ fieldId: name }, function (res) { r = res.data; }); return r; }

    $(document).on('change', '#systemowner5', function(e) {
    var userListControl = GetControl('systemowner5'); //Gets your userlist control
        var selectedFullName = $(userListControl).find("option:selected").text(); //Gets selected fullname
        Set('systemowner5FullName', selectedFullName); //Sets fullname to mentioned control
    });

    Hope this helps!

     

    1
    Comment actions Permalink
  • Avatar
    vd

    Thank you, Loren!!  That worked and does exactly what I need it to do.  Your instructions were very easy to follow and I appreciate you having sent the JavaScript code (since I don't know JavaScript!).  Thanks again!  

    0
    Comment actions Permalink
  • Avatar
    vd

    Thank you Sampat as well!

    0
    Comment actions Permalink
  • Avatar
    Loren Bratzler

    Sampat - Very nice, condensed solution! 

    By the way, how were you able to create the box with the scroll bar at the bottom in your post that has the code in it?  

     

    0
    Comment actions Permalink
  • Avatar
    Sampat Patil

    Hi Loren, The editor has paragraph styling as shown in below image!

     

    0
    Comment actions Permalink
  • Avatar
    Loren Bratzler

    Got it!  Thanks for showing me that!!

    {
    var dropDownSelectName = dropdownDisplayValue("systemowner5");
    setFieldNameObjectValue("SystemOwnerName",dropDownSelectName);
    }

    function dropdownDisplayValue(dropdownFieldName)
    {
    var dropDownSelectObj = getFieldNameObject(dropdownFieldName);
    var dropDownSelect = dropDownSelectObj.find("option:selected").text();
    return dropDownSelect;
    }

    function getFieldNameObject(fieldName)
    {
    var fieldObj;
    eFormHelper.getField({ fieldId: fieldName }, function (result) { fieldObj = result.data; });
    return fieldObj;
    }

    function setFieldNameObjectValue(fieldName, val)
    {
    eFormHelper.setFieldValue({ fieldId: fieldName, value: val });
    }
    0
    Comment actions Permalink

Please sign in to leave a comment.