log.debug('In Map Stage'); var searchR...
# suitescript
p
log.debug('In Map Stage'); var searchResult = JSON.parse(context.value); var WOID = searchResult.id; var appliedtointernalid = searchResult.values[{name: 'internalid', join: 'appliedToTransaction'}];
s
The first line you are JSON.parse() something, that is turning it into a JSON object. Just log that and you will see that to get the values you need
searchResult.values['appliedToTransaction.internalid']
, soemthing close to that.
It is no longer a searchResult type, that
name
and
join
prop are gone by the time it gets into map stage.
p
I keep on getting the result appliedtointernalid is undefined for var appliedtointernalid = searchResult.values['appliedToTransaction.internalid'];
s
Log searchResult.values, you will properties on there, i don't know the exact syntax it will be.
p
I get searchResult is [object Object]
b
How are you logging it
p
log.debug('searchResult is '+searchResult );
s
It's not a string, you ant add a string to an object in one line. Use both arguments of the log call... log.debug('searchResults', searchResults)
p
how can I get the details
ok I changed it to function map(context) { log.debug('In Map Stage'); var searchResult = JSON.parse(context.value); log.debug({ title: 'The Search Result', details: 'searchResult: ' + searchResult });
I still get searchResult: [object Object]
b
Dont log that way
p
how should I log it
b
you are adding an object to a string
in javascript, that means that the object will be converted to a string, and then concatenated to the string
that means your code is basically
'searchResult: ' + searchResult.toString()
the toString of any object is [object Object]
you want to use JSON.stringify() to print the contents of your object
p
I got it
b
that could be
Copy code
log.debug({
  title: "The Search Result",
  details: "searchResult: " + JSON.stringify(searchResult),
});
or more normally in suitescript
Copy code
log.debug({
  title: "The Search Result",
  details: searchResult,
});
the logging module automatically stringifies objects
p
thanks
and I was able to get the value: {"value":"1294173","text":"1294173"}
thank you both
one more question. can you use this function to get the value to be able to open a record? var appliedtointernalid = searchResult.values["internalid.appliedToTransaction"];
b
not sure what column you are working with, but in general the value of a select option is the internal id and the text is the name
p
I am working with getting the internal id of the applied to transaction and setting the corresponding line on the sales order
b
still doesnt tell me what column you are working with
there are multiple choices with the applied to transaction join
share the code used to generate the search
p
I created a saved search that limits the applied to transaction to the invoice
I meant to say
message has been deleted
so there should only be one applied to transaction for each instance
b
you have 2 choices for getting the applied to transaction's internal id
the applied to transaction : internal ID column will only have the internal id as its string value
the applied to transaction column will have an object as its value
the object will have 2 keys, a value and text
with the value being the internal id and the text the name of the transaction
p
got it. can i use that field in a var soRecord = record.load({ type: record.Type.SALES_ORDER, id: recordId });?
b
if recordId has a value internal id in it, sure
p
awesome! thank you so much
need one more piece of help. how do you just get the value for searchResult.values["internalid.appliedToTransaction"];? it returns the text and value
b
its an object
same way you access the keys of any other object
p
got it
thanks for all your help