Saturday, March 30, 2019

How to get built-in list selection ID to be used with SuiteScript and Web Services

When searching in SuiteScript (or Web Services) for Transactions with a specific Status (or in similar scenarios), it is necessary to specify correct filter criteria. For example, correct value for "Open" in Invoice Status field is "CustInvc:A".

To get correct value for any other Field selection, create a Saved Search, load it in SuiteScript and see its contents.

1) Deploy following Suitelet in your account:

function suitelet(request, response) {

  var searchid = request.getParameter('searchid');

 

  if (searchid != null) {

    var search = nlapiLoadSearch(null, searchid);

      // Load Saved Search with Internal ID = searchid

 

    response.write('<html><body>');

    var filters = search.getFilters();

      // Get Criteria of the loaded Saved Search

 

    for (filter in filters) {

      response.write(filters[filter]+'<br/>');

        // Print each Criteria line

    }

    response.write('</body></html>');

  } else { response.write('<html><body>searchid required</body></html>'); }

}

2) Create a Saved Search with your desired criteria, for example:
Search type: Transaction
Status is any of: Estimate:Open, Invoice:Open, Purchase Order:Partially Received, Sales Order: Pending Billing

3) Load the Suitelet from (1) with additional argument in the URL: &searchid=[id] where [id] is Internal ID of Saved Search created in step (2)

4) List Internal IDs for the conditions stored in your Saved Search will be returned. Output for the example Search created in step (2) looks like this:

nlobjSearchFilter(status, null, anyof, [Estimate:A, CustInvc:A, PurchOrd:D, SalesOrd:F])

That means:
Estimate:A is Estimate: Open
CustInvc:A
is Invoice: Open
PurchOrd:D
is Purchase Order: Partially Received
SalesOrd:F
is Sales Order: Pending Billing

No comments:

Post a Comment