Zapier: Get Row ID based on 2 or more fields

I saw this thread but I still need help with this same concept because I’ve never used Code by Zapier. I am trying to add new expenses from QBO into Glide based off conditions. First, the expense in QBO has to be in the account called “Uncat”. That part works with Filter by Zapier. Then, I have to use Get All Rows in Glide because I’m trying to find a specific Vendor from my Glide Big Table based off the “QBO ID” of the Vendor in Glide. The QBO ID must match the QBO ID of the “New Expense” from QBO in the first step, or really the second step - Filter by Zapier. But I also need the Vendor to only be for the company that this Zap is for - because there are very many companies with very many vendors, so vendors could have the same QBO ID but be for different companies, and I can’t mix up the Vendor and use a Vendor from the wrong company. So, I need the Code by Zapier to somehow find the correct vendor for the correct company based off the Row ID for this specific company, which I can set manually for this Zap and each companies’ Zap, and then find the Vendor for that company that has the same QBO ID in Glide as the QBO ID in the QBO New Expense/Filter by Zapier. See screenshots for the Zap. The main part I need help with is the Code by Zapier but I’ve also never used Glide in Zapier because I’m used to Airtable, so I’m open to any and all feedback

This is code I use for that find Row ID step

let userIDs = inputData.userIDs.split(",");
let rowIDs = inputData.rowIDs.split(",");

let index = userIDs.findIndex(userID => userID.includes(inputData.search));

if (index !== -1) {
    // If the userID is found, return the corresponding rowID
    output = { rowID: rowIDs[index] };
} else {
    // If the userID is not found, handle the case accordingly
    output = { rowID: null }; // Or any other default value
    // You can also return null or an empty string if that makes more sense
    // output = { rowID: null }; 
    // output = { rowID: "" }; 
}

You could put this into like a ChatGPT or the Zapier AI to edit so you can check for more fields or you’d have to do a few steps together to chain them to ensure you get the right vendor.

Sounds like your flow looks like this. As per @chanwise 's post above, you can use JavaScript to check that.

Would your Get All Rows step return all vendors’ IDs and companies’ IDs?

Yes, that’s correct. The Glide Big Table gets all Vendors for all of our Companies. Each Vendor has a Row ID and a Company Row ID, which links the Vendor to the correct Company as a Relation. For this Zap, I can define the Company Row ID manually because I set up a Zap separately for each Company’s QuickBooks. Then I just need the Code by Zapier to make sure the Vendor with the correct QBO ID also has the correct Company Row ID that I define. I tried using Zapier AI like @chanwise mentioned, but it feels like I’m trying to read a different language

What I would suggest, build a sample table with some staged data of what you need to pull as fields and then use that in ChatGPT where you ask to modify my code or create new code using JavaScript to pull the RowID field based on the other two columns. I found it to be better than Zapier AI since you can add additional inputs to help get what you want

You can start with something like this and adjust as needed.

let qboVendorId = inputData.qboVendorId; // QBO Vendor ID from the new expense
let companyId = inputData.companyId; // Company ID for this specific Zap
let glideRows = inputData.glideRows; // All rows from Glide Big Table

// Function to find the matching vendor
function findMatchingVendor(rows, qboId, company) {
  return rows.find(row => 
    row.qbo_id === qboId && 
    row.company_id === company
  );
}

// Find the matching vendor
let matchingVendor = findMatchingVendor(glideRows, qboVendorId, companyId);

if (matchingVendor) {
  output = {
    found: true,
    vendorId: matchingVendor.id,
    vendorName: matchingVendor.name,
    // Add any other vendor details you need
  };
} else {
  output = {
    found: false,
    message: "No matching vendor found for the given QBO ID and Company ID"
  };
}