Saved search to get vendor bill line level details and related purchase order details using same saved search.

let filterArr = [

            [“type”, “anyof”, “VendBill”],

            “AND”,

            [“subsidiary”, “anyof”, “7”, “3”],

            “AND”,

            [“status”, “anyof”, “VendBill:D”, “VendBill:E”],

            “AND”,

            [“taxline”, “is”, “F”],

            “AND”,

            [“cogs”, “is”, “F”],

            “AND”,

            [“shipping”, “is”, “F”],

            “AND”,

            [

              [

                [“mainline”, “is”, “T”]

              ],

              “OR”,

              [

                [“mainline”, “is”, “F”],

                “AND”,

                [“item”, “noneof”, “@NONE@”] // This ensures you only get item lines

              ]

            ],

            “AND”,

            [“appliedtotransaction.type”, “anyof”, “PurchOrd”, “@NONE@”],

            “AND”,

            [“customform”, “anyof”, “321”]

          ];

columns:

            [

              search.createColumn({ name: “approvalstatus”, label: “Approval Status” }),

              search.createColumn({ name: “transactionnumber”, label: “Transaction Number” }),

              search.createColumn({ name: “tranid”, label: “Document Number” }),

              search.createColumn({ name: “appliedtotransaction”, label: “Applied To Transaction” }),

              search.createColumn({

                name: “custbody_jj_ee_customer_po”,

                join: “appliedToTransaction”,

                label: “Customer PO#”

              }),

              search.createColumn({ name: “entity”, label: “Name” }),

              search.createColumn({ name: “duedate”, label: “Due Date/Receive By” }),

              search.createColumn({ name: “item”, label: “Item” }),

              search.createColumn({ name: “quantity”, label: “Quantity” }),

              search.createColumn({ name: “rate”, label: “Item Rate” }),

              search.createColumn({ name: “amount”, label: “Amount” }),

              search.createColumn({ name: “total”, label: “Amount (Transaction Total)” }),

              search.createColumn({ name: “line”, label: “Line ID” }),

              search.createColumn({ name: “internalid”, label: “Internal ID” })

            ]

        });

        let searchResultCount = transactionSearchObj.runPaged().count;

        log.debug(“searchResultCount”, searchResultCount)

        let billArray = {

          itemLines: []

        };

        transactionSearchObj.run().each(function (result) {

          let purchaseOrderNum = ”;

          let approvalStatus = result.getText({ name: “approvalstatus”, label: “Approval Status” });

          log.debug(“Approval Status”, approvalStatus)

          let docNum = result.getValue({ name: “transactionnumber”, label: “Transaction Number” });

          log.debug(“doc num”, docNum)

          let billNum = result.getValue({ name: “tranid”, label: “Document Number” });

          log.debug(“billNum”, billNum)

          let poNum = result.getText({ name: “appliedtotransaction”, label: “Applied To Transaction” });

          if (poNum.includes(“Purchase Order #”)) {

            purchaseOrderNum = poNum.split(“Purchase Order #”)[1].trim();

          }

          let custPO = result.getValue({

            name: “custbody_jj_ee_customer_po”,

            join: “appliedToTransaction”,

            label: “Customer PO#”

          });

          let custName = result.getText({ name: “entity”, label: “Name” });

          log.debug(“cust name”, custName)

          let line = result.getValue({ name: “line”, label: “Line ID” });

          log.debug(“line”, line)

          log.debug(“line (typeof)”, typeof line);

          // Convert line to a number for comparison

          let lineNumber = parseInt(line, 10);

          log.debug(“line (parsed as number)”, lineNumber);

          if (lineNumber == 0) {

            vendorName = custName;

          }

          log.debug(“vendor name”, vendorName)

          let duedate = result.getValue({ name: “duedate”, label: “Due Date/Receive By” });

          let item = result.getText({ name: “item”, label: “Item” });

          let quantity = result.getValue({ name: “quantity”, label: “Quantity” });

          let rate = result.getValue({ name: “rate”, label: “Item Rate” });

          let itemAmt = result.getValue({ name: “amount”, label: “Amount” });

          let totalAmt = result.getValue({ name: “total”, label: “Amount (Transaction Total)” });

          log.debug(“total amount”, totalAmt)

          let internalId = result.getValue({ name: “internalid”, label: “Internal ID” });

          log.debug(“internalId”, internalId)

          if (lineNumber != 0) {

            log.debug(“*****”)

            billArray.itemLines.push({

              approvalStatus: approvalStatus,

              billNum: billNum,

              docNum: docNum,

              purchaseOrderNum: purchaseOrderNum,

              custName: custName,

              custPO: custPO,

              vendorName: vendorName,

              duedate: duedate,

              item: item,

              quantity: quantity,

              rate: rate,

              itemAmt: itemAmt,

              totalAmt: totalAmt,

              line: line,

              internalId: internalId

            });

          }

          return true;

        });

Leave a comment

Your email address will not be published. Required fields are marked *