RE: Weird JSON/Saved Search Issue

I am building a script that uses a Search to collect the carton items from the Inventory Details for an Item Fulfillment

/**
* @NApiVersion 2.1
* @NScriptType UserEventScript
*/
define([‘N/record’, ‘N/log’, ‘N/search’ ], function(record, log, search) {
function beforeLoad(context) {

//Log our enteties
if(context.type === context.UserEventType.VIEW){
//Get the Fulfillment Record ID
var fulfillmentRecordID = context.newRecord.id;
log.debug(“Fulfillment Id”,fulfillmentRecordID);

var inventorydetailSearchObj = search.create({
type: “inventorydetail”,
filters:
[
[“pickcarton”,”isnotempty”,””],
“AND”,
[“transaction.internalid”,”anyof”,fulfillmentRecordID]
],
columns:
[
search.createColumn({name: “pickcarton”, label: “Pick Carton”})
]
});

let inventorydetailSearchResults = inventorydetailSearchObj.run().getRange({
start: 0,
end: 100
});

log.debug(“ID Search Results”,inventorydetailSearchResults)

const uniquePickcartons = [];

for(let i = 0; i < inventorydetailSearchResults.length; i++){
let item = inventorydetailSearchResults[i];

log.debug(“values”,item.values);

}

}
};

 

return {
beforeLoad: beforeLoad
};
});

 

When I log.debug item.values or item[“values”] I get a blank even though the Item JSON is

{
      recordType: "inventorydetail",
      id: "4172470",
      values: {
         pickcarton: "2"
      }
   }
RedHeadHunt Rookie Asked on December 28, 2023 in SuiteScript.
Add Comment
1 Answers

This is because the `item` variable is a `N/search.Result` instance. This is not the same thing as the `JSON` representation output by `JSON.stringify()` which the `log` methods use internally. In a `Result` instance, the properties are intended to be accessed via its `getValue` or `getText` methods.

I suspect what you want is

    item.getValue({ name: ‘pickcarton’ })

See also:

Beginner Answered on December 28, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.