Load list data into vLookup tab.

Forums vLooup for SharePoint Load list data into vLookup tab.

This topic contains 6 replies, has 2 voices, and was last updated by  Alexander Bautz 1 week, 4 days ago.

  • Author
    Posts
  • #18553

    mk3jamie
    Participant

    I basically have an employee list and a vLookup that allows you to add training certificates to the employee list item. When I open my certificate vLookup tab, i have an employee name field that i want to populate directly from the main employee list item i’m currently editing.

    Is it possible to populate that vLookup when I open the tab and start filling out the vLookup list item? I.e populate it with the Employee name directly from the main list item i’m currently editing.

    Thanks again as always Alex.

  • #18580

    Alexander Bautz
    Keymaster

    Hi,
    You can add a button in the vLookup list view to update the value. Please note that you must load the vLookup data before you run this code (by showing the vLookup child table) because the snippet uses the dataobject to know which items to update.

    Add this code to the Custom JS:

    function callMeFromButton(){    
    	jQuery.each(spjs.vLookup.dataObj.vLookupTasks[spjs.dffs.data.thisItemID].items,function(id,vLookupListItem){
            spjs.utility.updateItem({
                "listName":"THE_LIST_GUID_OF_CHILD_LIST",
                "id":id,
                "data":{"Title":"Updated title!"}
            });
        });
    }

    Change “vLookupTasks” with the name of your vLookup field, and “THE_LIST_GUID_OF_CHILD_LIST” with the GUID or display name of your child list and finally the “data” object with the key-value-pairs to set the field values like my example that updates the Title field.

    Let me know how this works out.

    Alexander

  • #18592

    mk3jamie
    Participant

    Here’s what I have so far Alex.

    function callMeFromButton(){
    jQuery.each(spjs.vLookup.dataObj.vLookupTraining[spjs.dffs.data.thisItemID].items,function(id,vLookupListItem){
    spjs.utility.updateItem({
    “listName”:”Training and Accreditation”,
    “id”:id,
    “data”:{“Employee_x0020_Name”:”Full_x0020_Name_x0020_Text”}
    });
    });
    }

    So the vLookup is contained on the Employee List, i’ve reference the correct vLookup at the top to the Training and Accreditation list. Then inside the “data” element I’ve put in the field within the Training and Accreditation list I want to populate with the corresponding value from the employee list. I’ve used their internal names.

    I’m guessing I need to add code in to link the function to a button so to trigger it on the list?

    Thanks again for your help Alex.

  • #18595

    mk3jamie
    Participant

    Forgot to mention as well, the vLookup loads an InfoPath form, if that makes any difference.

  • #18597

    Alexander Bautz
    Keymaster

    You need to call the function either automatically every time you show the vLookup table (but this might be unnecessary) or by a button like this:

    Add a HTML section to a tab, you can look at the help text to show how to create a button – basically something like this:

    <input type="button" value="Update vLookup children" onclick="callMeFromButton();return false;">

    I don’t think it matters that this is a infopath form as long as the source is a SharePoint list.

    Alexander

  • #18599

    mk3jamie
    Participant

    Have it working as you described Alex. Added the button into the vLookup that will assign the value from my employee name directly to the employee name field on the vLookup.

    My issue now is that Employee Name is the field I used to connect the vLookup to the Employee list. So because I’m wanting to set that automatically, the vLookups will not display as I’ve not set an employee name. Because they don’t display, I cannot use the button to assign the Employee name to them.

    Is there a way I can connect the Employee list and the vLookup together without using the employee name? Or would i just have to use another field that would need to be filled in on the vLookup list so to connect it to the main employee list?

    Hopefully that makes sense!

    Thanks again Alex.

  • #18669

    Alexander Bautz
    Keymaster

    Sorry for the delay. I’m not sure I understand exactly, but you can use the “_vLookupID” and “_vLookupParentID” as described in this guide: http://spjsblog.com/vlookup-for-sharepoint/vlookup-setup-example-for-sp-2010-and-2013/

    Alexander

You must be logged in to reply to this topic.