In SuiteScript how to prevent search from prepending itemid with parent's itemid and a colon

28 Views Asked by At

I have an item record which has the parent field set. When I look on the web page of this item record, I see its itemid

ITEM NAME/NUMBER
CHILD-ITEMID

Sorry, had to censor the actual itemid.

item's page screenshot

Also when I use the NetSuite field explorer plugin I also see the same value, which is what I expect, it's correct.

But when I try to get the itemid via the SuiteScript N/search module

require([
  'N/search',
], function (search) {
  const searchIns = search.create({
    type: 'serializedassemblyitem',
    filters: ['internalid', 'is', '123123',],
    columns: ['itemid',],
  });
  const results = searchIns.run();
  results.each((r) => {
    console.log('here');
    console.log(r.getValue('itemid'));
  });
});

I get:

PARENT-ITEMID : CHILD-ITEMID

If I use the N/record module, it's correct, but I need to use the N/search. Is it possible?

1

There are 1 best solutions below

2
bknights On

You can use a formula to remove the prefix

...columns:[
'itemid',
search.createColumn({name:'formulatext', formula:"REGEXP_REPLACE({itemid}, '.*:\\s?', '')"})

]

or if there is a possibility of the parent name having a colon : then something like the below works. The wrapping REGEXP_REPLACE cleans the colon and space prefixing the basic name.

search.createColumn({name:'formulatext', formula:"REGEXP_REPLACE(REPLACE({itemid}, nvl({parent}, ''), ''), '.*:\\s?', '')"})