-
-
Save axilaris/70a24cd73b76f3d6b6bbd0f8681518eb to your computer and use it in GitHub Desktop.
| /** | |
| * @NApiVersion 2.1 | |
| * @NScriptType Restlet | |
| */ | |
| define([ | |
| "N/log", | |
| "N/search", | |
| ], function (log, search) { | |
| function post(context) { | |
| log.debug('POST1 Context', context); | |
| return JSON.stringify(getCustomRecords(context)); | |
| } | |
| function getCustomRecords(context) { | |
| var mycustomSearch = search.create({ | |
| type: search.Type.CUSTOM_RECORD + '1589', | |
| title: 'Search Title', | |
| id: 'customsearch_my_second_so_search', | |
| columns: [{ | |
| name: 'id' | |
| }, { | |
| name: 'custrecord3987' | |
| }], | |
| filters: [{ | |
| name: 'custrecord3987', | |
| operator: search.Operator.EQUALTO, | |
| values: [context.custrecord3987] | |
| }], | |
| }); | |
| return mycustomSearch; | |
| } | |
| return { | |
| post: post, | |
| }; | |
| }); |
| ... | |
| payload = { | |
| "custrecord3987": "12345678", | |
| } | |
| ... |
@axilaris
You need to use search.Operator.IS for text fields. Here you go:
function getCustomRecords(context) {
var results = [];
search
.create({
type: search.Type.CUSTOM_RECORD + "1589",
columns: ["custrecord3987"],
filters: [
[
"custrecord3987",
search.Operator.IS,
context.custrecord3987,
],
],
})
.run()
.each(function (result) {
var id = result.id;
var field1 = result.getValue({
name: "custrecord3987",
});
results.push({ id: id, custrecord3987: field1 });
return true;
});
return results;
}
@naschumer thank you so much, it worked! really really appreciate it.
Out of curiousity, how do you know which operator to use for the types, I'd like to know.
@axilaris
Just from experience! Some times you can just try them until one works, usually IS, EQUALTO or ANYOF if it's one thing equaling another thing.
Another thing that you can do, you can build the Saved Search inside NetSuite using the UI, add the columns and filters as well. Then use this chrome extension:
https://chrome.google.com/webstore/detail/netsuite-search-export/gglbgdfbkaelbjpjkiepdmfaihdokglp
And it will turn that search into suitescript 2.0 code that you can paste into your script. Then you won't even need to think about the syntax of the columns/filters.
Hope this helps!
Another great chrome extension: https://chrome.google.com/webstore/detail/netsuite-field-explorer/cekalaapeajnlhphgdpmngmollojdfnd
Thank you!
@naschumer
custrecord3987 is Free-Form Text
refer to this screenshot -> https://i.imgur.com/zY2LohZ.png
as to the payload, its simply like this :
I dont pass in id like in the search.lookupFields example you gave