I have a grid full of items. The requirement is that the user scans a UPC code, or enters an item number, the grid automatically scrolls to that item in the grid, a quantity text box is focused on, and highlighted. The user enters a quantity, and scans the next item. This was working sort of. The findItem function is called on the change event of the item number field. The item is found in the grid and the grid scrolls to that item. However, I'm getting a null object when trying to .focus() and .select() the text box so the user can enter data. This is the JS Code:
Code: Select all
function findItem(itemIn) {
ajaxJSON({
url: "/profoundui/universal/SBTValidItem",
params: {
itemNumber: itemIn
},
method: "get",
async: false,
handler: function (ob) {
if (ob.success) {
var x = findRow(ob.itemNumber);
if (x === 0) {
this.focus();
var thisItem = getObj("txtItemNumber");
pui.errorTip(thisItem, "Item not found in grid");
thisItem.focus();
thisItem.select();
} else {
setTimeout (function() {
this.focus();
pui.set("txtItemNumber",ob.itemNumber);
let myGrid = getObj("Grid1");
myGrid.grid.scrollToRow(x);
let myCount = "txtCount." + x;
let objCount = getObj(myCount);
objCount.focus(); <--- here is where the code fails. Says objCount is null
objCount.select();
},200);
}
}
else {
this.focus();
var thisItem = getObj("txtItemNumber");
applyProperty(thisItem, "set focus ", "true");
applyProperty(thisItem, " field type ", "textbox");
pui.errorTip(thisItem, "Invalid Item/UPC Number");
thisItem.select();
}
}
});
}
function findRow(itemNumber) {
var myGrid = getObj("Grid1");
var recordCount = myGrid.grid.getRecordCount();
var found = 0;
myGrid.grid.scrollToRow(recordCount);
myGrid.grid.scrollToRow(1);
for (var x = 1; x <= recordCount; x++) {
var curItem = myGrid.grid.getDataValue(x, "SFITM#");
if (itemNumber == curItem) {
var count = getObj("txtCount." + x);
found = x
return found;
}
}
return found;
}