Skip to content

Instantly share code, notes, and snippets.

@axilaris
Created October 19, 2021 07:42
Show Gist options
  • Save axilaris/70a24cd73b76f3d6b6bbd0f8681518eb to your computer and use it in GitHub Desktop.
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",
}
...
@naschumer
Copy link

@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;
}

@axilaris
Copy link
Author

@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.

@naschumer
Copy link

naschumer commented Oct 20, 2021

@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!

@naschumer
Copy link

@axilaris
Copy link
Author

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment