Send vLookup data in a workflow email

Forums vLooup for SharePoint Send vLookup data in a workflow email

This topic contains 1 reply, has 2 voices, and was last updated by  MYH 4 months, 3 weeks ago.

  • Author
    Posts
  • #20731

    Alexander Bautz
    Keymaster

    I got a question from Michel Hayek regarding sending the vLookup table data in a workflow email.

    This is not possible without pulling the data from the vLookup data object and writing it to a multiline text field in your form. This is because the vLookup data only “lives” in the browser, and is not stored in the list item when you save the form.

    To write the data to a multiline field when the form is saved you can use this snippet in your Custom JS. Replace vLookupTasks with the vLookup field name in your form, and Multiline with the multiline field you want to store the data in.

    function dffs_PreSaveAction(){
        write_vLookup_to_multiline("vLookupTasks","Multiline");
        return true;
    }
    
    function write_vLookup_to_multiline(vLookuField,targetField){
        var b = [], val;
        b.push("<table cellpadding='4' cellspacing='0'>");
        // Header row
        b.push("<tr>");
        jQuery.each(spjs.vLookup.dataObj[vLookuField][spjs.dffs.data.thisItemID].fields,function(fin,disp){
            b.push("<th valign='top'>"+disp+"</th>");
        });
        b.push("</tr>");
        // Body
        jQuery.each(spjs.vLookup.dataObj[vLookuField][spjs.dffs.data.thisItemID].items,function(i,item){
            b.push("<tr>");
            jQuery.each(spjs.vLookup.dataObj[vLookuField][spjs.dffs.data.thisItemID].fields,function(fin,disp){
                val = item[fin] !== null ? item[fin] : "";
                val = val.split("<").join("<").split(">").join(">");
                b.push("<td valign='top' style='"+(i%2===1?"background-color:#eaeaea;":"")+"'>"+val+"</td>");
            });
            b.push("</tr>");
        });
        b.push("</table>");
        setFieldValue(targetField,b.join(""));
    }

    Please note that the styling of the table must be done by adding inline style tags to the <tr> or <td> (like I have done to add color to alternating rows). The SharePoint stylesheets will not affect the layout when it is rendered in the email client of the user so you will have to experiment until you find your preferred style.

    Please note that the vLookup table must be made visible in a tab before saving the item for the vLookup dataObj to be available for this script.

    Hope someone finds this useful.

    Alexander

  • #20749

    MYH
    Participant

    Okay, thank you Alexander it worked for me.

You must be logged in to reply to this topic.