I have a script that load a saved search it read t...
# suitescript
s
I have a script that load a saved search it read the column 0, which is the SO, and it return the SO #. It's all fine. However if the Saved search is changed and the first colums is the city, the script is going crazy. Instead of using the Column Number I would like to user the Name of the column. I tried this but it did not work log.debug(' ','getValue=' + result.getValue(search_columns[0]) +' name=' +result.getText(search_columns[0]) Any idea
e
What is the ID of the column you want to read?
s
I want to find the column that has the name "SO" and return the corresponding search_columns[???]
e
What field is the column named "SO" reading?
s
In this case it's the first one, but if they change it, like they were about to do it, the script would have gone crazy
e
OK let me ask a different way. What field from the Sales Order does your script expect to be first in the search columns?
s
It's a saved search
all the fields in the saved search
The script is reading the saved search
e
I understand
But clearly, in your script, the order of the columns matters
s
Whatever the order is, I want to know the name of the column, That's all I'm looking for
e
Column instances have a
name
and a
label
property
a
You can also load the search, add the column you need with a refence ID/Name you know, then run the search and get your results. This means that even if somebody remove the column from the search you still get your column value.
s
Possible but it will be a performance nightmare. I can use result.*getValue*(search_columns[0]) I'm searching for the name of that column something like result.*getText*(search_columns[0])
e
search_columns[0].name
or
search_columns[0].label
s
If that's the solution, I will be ashame of me. Thanks a lot
e
I imagine you'll have to do something like
Copy code
let theIndex = search_columns.find(c => c.label === 'SO')
// ...
result.getValue(search_columns[theIndex])
But then that breaks if the user changes the label, so this all feels a bit brittle
a
Loading/adding a column and running the search should not be a big performance penalty.
s
I tried label, name, find and none worked 😞
e
You're going to have to share code
n
I am guessing your SO number is tranid. So try this, result.getValue({name : 'tranid'})
👍 1
e
^ This is what I was desperately trying to uncover by asking what field "SO" was
s
Thanks all This result.getValue({name : 'tranid'}) was the answer
🌈 1