SuiteTalk – Custom Lists Example in C#

Here is an example of code I use to read any custom list and create a Dictionary<string, long> of the result.

Custom lists can be found at: Customization >> List, Records, & Fields >> Lists

Menu

Here is an example of a custom list:

Custom List Example

Simply call this method, passing the scriptId of the list you want to be returned as a Dictionary<string, long>.

VS Method

Here is the code so you can paste it into your project:

public static Dictionary<string, long> GetCustomListValues(
NetSuiteService service, string custom_list_name)
{
Dictionary<string, long> results = new Dictionary<string, long>();

CustomListSearchBasic basic = new CustomListSearchBasic()
{
scriptId = new SearchStringField()
{
@operator = SearchStringFieldOperator.@is
,
operatorSpecified = true
,
searchValue = custom_list_name
}
};

service.tokenPassport = NSExtensions.TBAtoken.createTokenPassport();
SearchResult result = service.search(basic);

if (result.status.isSuccess)
{
RecordRef recordRef = new RecordRef();
recordRef.internalId = ((CustomList) result.recordList[0]).internalId;
recordRef.type = RecordType.customList;
recordRef.typeSpecified = true;

service.tokenPassport = NSExtensions.TBAtoken.createTokenPassport();
ReadResponse response = service.get(recordRef);

if (response.status.isSuccess)
{
CustomList list = (CustomList) response.record;
foreach (CustomListCustomValue value in list.customValueList.customValue)
{
results.Add(value.value, value.valueId);
}
}
}

return results;
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s