Skip to content

Commit

Permalink
Improve purchasing auto-resolving of vendor (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber authored Jan 31, 2024
1 parent 70012e2 commit c8a9f57
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions LabPurchasing/resources/queries/labpurchasing/referenceItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,28 @@ var LABKEY = require("labkey");
var console = require("console");

function beforeInsert(row, errors){
// Allow resulting vendorId from name:
if (row.vendorName && !row.vendorId) {
LABKEY.Query.selectRows({
schemaName: 'labpurchasing',
queryName: 'vendors',
columns: 'rowid',
filterArray: [LABKEY.Filter.create('vendorName', row.vendorName)],
sort: '-rowid',
maxRows: 1,
scope: this,
success: function(results) {
if (results.rows.length) {
row.vendorId = results.rows[0].rowId;
// The purpose of this is to allow the user to provide a string value for
// vendorId or vendorName, and attempt to resolve this against known vendors:
if (!row.vendorId || isNaN(row.vendorId)) {
var vendorName = row.vendorName || row.vendorId;
if (vendorName) {
LABKEY.Query.selectRows({
schemaName: 'labpurchasing',
queryName: 'vendors',
columns: 'rowid',
filterArray: [LABKEY.Filter.create('vendorName', vendorName)],
sort: '-rowid',
maxRows: 1,
scope: this,
success: function(results) {
if (results.rows.length) {
row.vendorId = results.rows[0].rowId;
}
else {
console.error("Unable to resolve vendor: " + vendorName);
}
}
else {
console.error("Unable to resolve vendorname: " + row.vendorName);
}
}
})
})
}
}
}

0 comments on commit c8a9f57

Please sign in to comment.