Hello, I am trying to get the value of the file.in...
# suitescript
p
Hello, I am trying to get the value of the file.internal id in a search. what am I doing wrong?
r
I am assuming mySearchResult is your search object. If the below doesn't work please share the above code as well.
Copy code
mySearchResults.run().each(function(result) {
    var fileid = result.getValue({
        name: 'internalid'
    });
    log.debug("fileid", fileid);
    return true;
});
p
its still not working. I have it json format:
how do I get the value of file.internalid?
there should only be one value returned
b
working with netsuite objects and logs relies on knowing that the log lies about the object
it actually logs the json form of the object (the result of calling the .toJSON method)
p
got it. so how can I get the value of file.internalid?
b
first off you need to learn how to work with arrays
you havent shared enough code to know for sure, but it appears to be an array, and arrays dont have a getValue method
p
message has been deleted
its returning a value for file.internalid
b
after you learn how to get to the individual elements of the array. you need to learn how to properly use the parameters to getValue
the basics are that you use the same parameters to create the columns as you do to get the value
p
ok
b
again , you havent shared enough code, but my guess is that your file variable is the N/file module, and that module has no property named internalid
r
if you can share the code from line 159 till 178, it will become easier to provide you the solution. Instead of a pic
p
var fileName = 'vendorlistfortr.csv' var mySearchResults = search.create({ type: 'folder', filters: [ ['internalid','is', 307416], 'AND', ['file.name','is', fileName] ], columns: [ search.createColumn({ name: 'internalid', join: 'file' }) ] }).run().getRange({ start: 0, end: 1 }); log.debug('mySearchResults',mySearchResults);
there is the code
r
use this
Copy code
var folderSearchObj = search.create({
    type: "folder",
    filters:[
       ["internalid","anyof","307416"], 
       "AND", 
       ["file.name","is", fileName]
    ],
    columns:[
       search.createColumn({name: "internalid",join: "file",label: "Internal ID"}),
    ]
});
var searchResultCount = folderSearchObj.runPaged().count;
log.debug("folderSearchObj result count",searchResultCount);

var result = folderSearchObj.run().getRange({
    start: 0,
    end: 1
});

for (var index = 0; result.length - 1 >= index; index++) {
    var fileid = result[index].getValue({name: 'internalid'});
    log.debug("fileid", fileid);
}
p
its not returning a value for fileid
r
I had one typo in the code, you can use now
p
it worked
thank you!
r
Do log the output from search.create() And search.run().getRange(). And go to helpcenter as well and search for the same. Will help you understand a bit better.
p
yes. thank you!