How to get values from a saved search in suitescri...
# ask-stanley-ai
n
How to get values from a saved search in suitescript if the saved search has two formulas of same kind like formula(text)
c
AI generated answer (using internal Slack threads):
To get values from a saved search in SuiteScript when the saved search has two formulas of the same kind like formula(text), you need to give each formula field a unique alias. This is because when the results are returned, the field names are used to identify the values. If two fields have the same name, one will override the other. Here's an example of how you can do this:
Copy code
javascript
var mySearch = search.create({
   type: "customrecord_my_custom_record",
   columns: [
      search.createColumn({
         name: "formulatext",
         formula: "{custrecord_field1}",
         label: "Formula Text 1"
      }),
      search.createColumn({
         name: "formulatext",
         formula: "{custrecord_field2}",
         label: "Formula Text 2"
      })
   ]
});
In this example, two formula text fields are created, each with a unique label. The label is used as the alias for the field, allowing you to differentiate between the two when you retrieve the results. When you run the search and loop through the results, you can access the values of these fields using their labels:
Copy code
javascript
mySearch.run().each(function(result) {
   var formulaText1 = result.getValue({name: "formulatext", label: "Formula Text 1"});
   var formulaText2 = result.getValue({name: "formulatext", label: "Formula Text 2"});
   // Do something with the values...
   return true;
});
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.84168148
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836968422
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835994184
Please provide your feedback on this answer.