Howdy folks! :wave: How do I return a value from ...
# suitescript
j
Howdy folks! ๐Ÿ‘‹ How do I return a value from a column using a saved search? I essentially just want to use the saved search to set variables:
Copy code
function runSavedSearch(newRecord) {
        var savedsearch = search.load({ id: 'customsearch_fulfillment_request_updat_6' });
        savedsearch.filters.push(search.createFilter({
            name: 'internalid',
            operator: <http://search.Operator.IS|search.Operator.IS>,
            values: newRecord.id
        }));
        var results = savedsearch.run();
            log.debug({title:'search results', details: results});
        return;

     }
b
go through the documentation for Search.run to see what it returns
the object it returns has 2 methods, each of which can get search results
j
@battk I changed it to do a get value, but it returns nothing
Copy code
var savedsearch = search.load({ id: 'customsearch_fulfillment_request_updat_6' });
        savedsearch.filters.push(search.createFilter({
            name: 'internalid',
            operator: <http://search.Operator.IS|search.Operator.IS>,
            values: newRecord.id
        }));
 
        var results = savedsearch.run();
            log.debug({title:'search results', details: results});
        savedsearch.run().each(function(result) {
            var slackwebhook = result.getValue({
                name: 'custrecord_slack_webook'
            });
            log.debug({
                title: "slackwebhook",
                details: slackwebhook
            })
            var vendreceipt = result.getValue({
                name: 'formulatext'
            });

            return true;
any idea whats wrong?
b
the guess would be that the search result has no value for that column
or that the column's id is wrong
the code itself is trying to do something weird
its trying to do a search on itself, which would only give search results related to itself
j
hmm
b
im not sure why you would need to do a search in that case
j
I suppose I dont need to, just trying to reference the context.record (new record) in my search
essentially I just need to pull in specific fields related to the item fulfillment, I have made the perfect saved search that I want to pass via webhook
so I want to run a search on my perfect saved search to grab certain values for that line item
are you saying that using the filter search is the issue?
b
you are adding a filter to the internal id, to limit search results to the newRecord's data
you already have access to the data in the newRecord
why are you doing a search
j
because I am having THE hardest time passing data related to the search through
I cant even pass through the status ๐Ÿ˜•
Copy code
log.debug({
                title: "transtatus",
                details: newRecord.transtatus
            })
returns nothing in debugging
b
newRecord is not an object
it does not have a key named transtatus
j
oh boy, I think I was forgetting the โ€œfieldsโ€ let me try that
b
the newRecord is a record.Record, the normal way to get data out of it are using one of the Record Object Members
๐Ÿ™ 1
j
I added the fields and was able to pass the proper transtatus thanks
but what method do you recommend for creating variables from a saved search using my newrecord as the search?
b
what you were doing before, using getValue
but the parameters of getValue must match that of the column you are getting
j
this is from by debug results of the saved search
message has been deleted
1. is it supposed to show the actual value in my log? 2. which name am I to reference to grab my value from said column?
by the way, thank you so much! very new to this!
b
Result.getValue has 4 parameters for its option's object
they must match the column's options