Is there a straight forward way to find a single i...
# suitescript
g
Is there a straight forward way to find a single item record by the itemid/name? Right now I'm using N/search and running essentially
search.create(...filters: ['name', 'is', 'myItemId']).run().getRange({start: 0, end: 10})[0].id;
s
What exactly do you want the item record for? search.lookupFields() is good for retrieving body level information if you know the id/type
Oh I just re-read, you don't know the internalid, and need to get it.
g
Yea, exactly.
b
you probably want to be using the nameinternal filter instead
name looks at multiple fields
g
Thanks, copy/paste error. The field I'm searching on n this case is
itemid
function findRecordIdByName(itemId) {
var recordSearch = search.create({
type: search.Type.ASSEMBLY_ITEM,
columns: ['internalid'],
filters: ['itemid', 'is', itemId],
});
var results = recordSearch.run()
.getRange({ start: 0, end: 10 });
if (results.length !== 1) {
return null;
}
return results[0].id;
}
Think I'm going with this.
b
modify one of your items to have a value in the display name that matches another item
search for that items name using your code
g
Are you expecting it to return two results? I was wondering about that. My item SKU's are tightly controlled, only my scripts are going to be managing item id's, user's are not able to set them up manually. So, I think this will be ok if that's what you're suggesting is a problem to watch out for.
b
itemid is the same as name, and they both look at multiple name related fields
nameinternal is the precise one that only looks at itemid
👀 1
g
Oh, that's really good info. Thanks @battk!