Send vLookup data in workflow email (2023 version)

Home Forums vLooup for SharePoint Send vLookup data in workflow email (2023 version)

Viewing 1 reply thread
  • Author
    Posts
    • #36611
      Notrega
      Participant

        Alexander – Using the code from this thread, https://spjsblog.com/forums/topic/send-vlookup-data-in-a-workflow-email/, and it works great. However in SharePoint the grouping and sorting (grouped by Status and then sorted by Item Type, but when the same data is pulled into the email it is grouped ok but the sorting is all jacked up.

        What do I need to add to this code to get to group by Status and then sort by Item Type?

        As always we appreciate all your support – beers on me come payday.

        Code below:

        function dffs_PreSaveAction() {
        write_vLookup_to_multiline({
        “fin”: “vLookupItem”, // Name of vLookup column
        “writeTo”: “Email_Table”, // Name of field to write to
        “groupBy”: “OrderStatus”, // Name of field to group by
        });
        write_vLookup_to_multiline({
        “fin”: “vLookupManualItems”, // Name of vLookup column
        “writeTo”: “ManualItemText”, // Name of field to write to
        “groupBy”: “OrderStatus”, // Name of field to group by
        });
        return true;
        }

        function write_vLookup_to_multiline(arg) {
        var b = [], val, arr = [];
        b.push(“<table cellpadding=’4′ cellspacing=’0′>”);
        // Header row
        b.push(“<tr>”);
        jQuery.each(spjs.vLookup.dataObj[arg.fin][getFieldValue(“_vLookupID”)].fields, function (fin, disp) {
        b.push(“<th valign=’top’>” + disp + “</th>”);
        });
        b.push(“</tr>”);
        // Body – make array of items
        jQuery.each(spjs.vLookup.dataObj[arg.fin][getFieldValue(“_vLookupID”)].items, function (i, item) {
        arr.push(item);
        });
        // Sort by groupBy field
        arr.sort(function (a, b) {
        if (a[arg.groupBy] < b[arg.groupBy]) {
        return -1;
        }
        if (a[arg.groupBy] > b[arg.groupBy]) {
        return 1;
        }
        return 0;
        });

        var groupHeaderTracker = {};
        jQuery.each(arr, function (i, item) {
        if (groupHeaderTracker[item[arg.groupBy]] === undefined) {
        groupHeaderTracker[item[arg.groupBy]] = true;
        b.push(“<tr>”);
        b.push(“<td colspan=’99’ valign=’top’ style=’padding:5px;background-color:#c5c5c5;’>” + item[arg.groupBy] + “</td>”);
        b.push(“</tr>”);
        }
        b.push(“<tr>”);
        jQuery.each(spjs.vLookup.dataObj[arg.fin][getFieldValue(“_vLookupID”)].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(arg.writeTo, b.join(“”));
        }

      • #36612
        Notrega
        Participant

          Never mind, I figured it out…

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.