Performing a Search Using NetSuite Connector in MuleSoft
This blog will guide you through performing search operations using the NetSuite connector in MuleSoft.
NetSuite searches can be executed in two main ways:
- Using a Predefined Saved Search: Retrieve records from an existing saved search in NetSuite by referencing its
savedSearchId
. - Creating Criteria in MuleSoft: Define search criteria directly within MuleSoft.
In this example, we will focus on executing a saved search by sending a SOAP request from MuleSoft to NetSuite. (SOAP, or Simple Object Access Protocol, is a protocol for exchanging structured information in web services using XML as the message format, enabling communication between applications over a network.)
Steps to Perform a NetSuite Search
Before diving in, it’s recommended to familiarize yourself with creating an XML file using DataWeave.
Step 1: Adding the NetSuite Connector in MuleSoft
Add the NetSuite connector to your project by dragging and dropping it from the Add Module section into your Mule palette.
Step 2: Configuring the NetSuite Connector
Drag the Search Operation from the Mule palette.
Click the plus icon to configure the NetSuite connector and fill in the required fields.
Step 3: Creating the NetSuite Search Request
Add a Transform Message shape before the NetSuite Search Operation. Expand it and write the DataWeave code for your request.
Use Case: Retrieve item saved search results from NetSuite with savedSearchId: '5927'
.
The resulting XML request will look like this:
Code Walkthrough:
- Include Namespaces:
- To perform a search operation, include the “Message Namespace.”
- Example:
ns prefix <namespace URI>
ns ns0 urn:messages_2020_2.platform.webservices.netsuite.com
- Note:
_2020_2
indicates the NetSuite version, which must match the SOAP port configured in the NetSuite connector.
- For an item search, include the Accounting Namespace.
- XML Structure:
- Provide a
searchRecord
field. - For
searchRecord
, you can either:- Use
savedSearchId
with theItemSearchAdvanced
type. - Create custom criteria using the
ItemSearch
type.
- Use
- Provide a
Example 1: Using savedSearchId
- Select
ItemSearchAdvanced
. - Include
savedSearchId
orsavedSearchScriptId
as attributes.
Example 2: Creating Criteria in the Request
- Select
ItemSearch
as the type and define criteria within the request.
Use Case: Search for items with:
- Type: Assembly
- Location: Hyderabad (
internalId: "1"
)
Code Walkthrough for Criteria-Based Search:
- Include the
search
field under the message namespace. - For
searchRecord
, select the normal search type (ItemSearch
). - Under
basic
, which is of typeItemSearchBasic
, define:- First Criterion:
- Field:
type
- Attributes:
operation
andsearchValue
- Multiple
searchValue
pairs can be separated by commas.
- Field:
- Second Criterion:
- Field:
location
- Type:
recordRef
- Use
internalId
as an attribute.
- Field:
- First Criterion:
Step 4: Transforming the Final Message
Add a Transform Message shape to process and display the final search result.
By following these steps, you can effectively perform search operations using the NetSuite connector in MuleSoft, whether by utilizing predefined saved searches or creating custom criteria within MuleSoft. These methods enable seamless integration with NetSuite and streamline data retrieval processes, making it easier to manage and manipulate data for your business needs.