I'm trying to work with a large dataset being retu...
# suiteanalytics
j
I'm trying to work with a large dataset being returned from a saved search in SS2.0. I'm using
runPaged()
then
fetch()
to get pages of results. My issue is that I have multiple
formulatext
fields, and I'm only ending up with one, as they are being indexed by
name
from the
searchColumn
, and of course they all have the name
formulatext
s
How are you retrieving them in the searchResult. You can use
result.getValue(result.columns[0])
,
columns[1]
etc. If you know the indexes of the columns, maybe just use the same column array for both the building and retrieval.
j
Yes I am using getValue, but the problem is before it gets that far it "loses" the earlier formulatext columns
Copy code
var pages = tx_search.runPaged({pageSize: 4000});
				
// Go through each page of results.
for(var p = 0; p < pages.pageRanges.length; p++) {
			
	// Get a page of results.
	var page = pages.fetch(p);

	// At this point, there is only one formulatext field left (the others are overwritten)

}
s
Where is the part where you are getting the value?
for example...
Copy code
let searchObj = search.create({
    type: 'customrecord_blah',
    filters: ['internalid', 'anyof', '1234'],
    columns: [
        search.createColumn({
            name: 'formulatext',
            formula: '{custrecord_blah_item}'
        }),
        search.createColumn({
            name: 'formulatext',
            formula: '{custrecord_blah_location}'
        }),
    ]
});

let res = searchObj.runPaged().fetch({index: 0}).data;
let result = res[0];
let colValue1 = result.getValue(result.columns[0]);
let colValue2 = result.getValue(result.columns[1]);
j
I get it later, but I can literally see already in this data that the columns are already lost.
s
They don't just get lost, the resultSet does not overwrite columns regardless of their name.
j
I even tried renaming the columns e.g. {name: 'formulatext_1'} and so on. I end up with just one called 'formulatext_4' and the others are gone.
They don't just get lost, the resultSet does not overwrite columns regardless of their name.
I think you are wrong
s
The block above is just 2 formulatexts, and they both come back fine
j
I have more than 4000 results.
page.data does NOT keep the extra formulatext columns
I'm logging page.data and the columns are missing
s
pageSize is maximum of 1k, so not sure how the 4k is relevant
Logging page.data as a whole is not the same as retrieving the data from the object and then logging.
j
I'm only using runPaged because I have > 4000 results
well I discovered the error because the other columns are coming back undefined when I try to get their values
The maximum number of results in a ResultSet object is 4000. If a search matches more than 4000 results, you must use Search.runPaged(options) or Search.runPaged.promise(options) to retrieve the full set of results.
s
yes, but the maximum size for a pageRange is 1k
j
My point was simply why I'm using this method rather than just a run().each
s
I understand that, I exclusively use runPaged(). It is not the problem.
b
share the code you are using ti get the formula fields
j
so basically I can't use page.data by itself, I HAVE to call getValue on every single column of every single row
seems to be the only way
b
share the code you are using to get the formula fields
j
hang on it's a bitcomplicated
let me strip it down
s
Page.data is an array of results, not an array of json objects. You need to retrieve the data from it the same way as if you ran the search using
run().each
or
run().getRange()
with getValue calls or toJSON() then reading the properties off of each result.
j
Maybe my stringify is just being super misleading
I have no idea....let me look into this further
s
something like this is prob what u want to do
Copy code
//array of results
let res = transactionSearchObj.runPaged().fetch({index: 4}).data;
res.forEach(function (result){
    let values = result.toJSON().values; //you would see formulatext and formulatext_1 properties here
})
b
without sharing any code
i will blindly tell you that your pageSize should be 1000
s
^
b
your code for getting pages should be more similar to getRange than run
and that netsuite does not handle formula fields consistently
you must use getValue with a column object as the parameter
you cannot use a simple object
j
I fixed my pageSize
bit surprised it didn't throw a warning
s
Yeah wonder if was just using the 1k limit anyway?
j
o.m.g. It's because my formula columns looked like this:
Copy code
search.createColumn({name: 'formulatext_1', formula: '', label: 'name of my column'}),
instead of this
Copy code
search.createColumn({name: 'formulatext_1', formula: '\'\'', label: 'name of my column'}),
facepalm
s
yeah tahts a pretty useless formula haha
j
well I want it to be blank
it's just a placeholder that's filled in with a bunch of stuff later on
but
it needed quotes in there to make an empty string
I guess invalid expressions don't throw an error, they just get excluded as columns
s
that seems strange/unexpected. It's usually pretty picky about malformed columns or filteres
j
thanks for staying by my side through this fun adventure
would like my afternoon back 😞