DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • JSON-Based Serialized LOB Pattern
  • Projections/DTOs in Spring Data R2DBC
  • Build a Java Microservice With AuraDB Free
  • How to Store Text in PostgreSQL: Tips, Tricks, and Traps

Trending

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • The Role of AI in Identity and Access Management for Organizations
  • What’s Got Me Interested in OpenTelemetry—And Pursuing Certification
  • Monoliths, REST, and Spring Boot Sidecars: A Real Modernization Playbook
  1. DZone
  2. Data Engineering
  3. Data
  4. Implementing NetSuite Add Records Operation With MuleSoft - Part II

Implementing NetSuite Add Records Operation With MuleSoft - Part II

In part one, we went through various use cases for performing search operations using the MuleSoft NetSuite connector. In part 2, let's see how to add records.

By 
Jitendra Bafna user avatar
Jitendra Bafna
DZone Core CORE ·
Aug. 20, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
7.3K Views

Join the DZone community and get the full member experience.

Join For Free

In my previous article, we have gone through various use cases for performing search operations using the MuleSoft NetSuite connector. Here, we will see how we can add records into NetSuite which consists of predefined fields, custom fields, and fields of type RecordRef.

Before we deep dive into various use cases, it is necessary to understand internalId and externalId fields in netsuite record type. Generally, each record type has internalId and externalId.

  • internalId:  Unique Id in netsuite for each record.
  • externalId:  Unique Id in the external system for each record. Generally, this is useful when we want to create or update or sync any records from the external system to netsuite.

Use Case 1: - Create Employee Record in NetSuite having predefined fields

We need to create records in NetSuite having predefined fields and no custom fields. We will be using a record type as Employee. Below is data mapping between the External System and Netsuite.

Sr No External System Fields Data Type (External System) Netsuite Fields
( NetSuite Employee)
Data Type
(NetSuite Employee)
1 FirstName string firstName string
2 MiddleName string middleName string
3 LastName string lastName string
4 isInactive boolean isInactive boolean
5 Mobile string mobilePhone string
6 Designation string title string
7 Id string externalId string

Dataweave transformation for the above data mapping will look as shown below and it is very straight forward.

JSON
 




x


 
1
%dw 2.0
2
output application/java
3
---
4
payload map ( payload01 , indexOfPayload01 ) -> {
5
    externalId: payload01.Id default '',
6
    firstName: payload01.FirstName default '',
7
    middleName: payload01.MiddleName default '',
8
    lastName: payload01.lastName default '',
9
    isInactive: payload01.isInactive default false,
10
    mobilePhone: payload01.Mobile default '',
11
    title: payload01.Designation default '',
12
}


To create records in NetSuite, we will be using the Add record operation available in the MuleSoft NetSuite connector, and under connector configuration, we will be using Token Authentication explained in my last article. Add above Dataweave in the Transform message component and placed in front of NetSuite Add Records connector.

adding employee in record type

Use Case 2: Extend above Dataweave to Add Custom Fields Data Mapping

We will be adding mapping for two custom fields custentity_empsalary, custentity_multiemail in NetSuite.

Sr No External System Fields Data Type (External System) Netsuite Fields
( NetSuite Employee)
Data Type
(NetSuite Employee)
1 Email string custentity_multiemail Custom Field (string)
2 Salary string custentity_empsalary Custom Field (string)

Dataweave for the above data mapping will look like as shown below and it is not straight forward for custom fields as you need to pass namespace.

JSON
 




x


 
1
%dw 2.0
2
output application/java
3
---
4
payload map ( payload01 , indexOfPayload01 ) -> {
5
    customFieldList: {
6
        customField: [{
7
            scriptId: "custentity_multiemail",
8
            value: payload.Email default '',
9
        } as Object {
10
            class: "org.mule.module.netsuite.extension.api.StringCustomFieldRef"
11
        },
12
        {
13
            scriptId: "custentity_empsalary",
14
            value: payload.Salary default '',
15
        } as Object {
16
            class: "org.mule.module.netsuite.extension.api.StringCustomFieldRef"
17
        }
18
        ]
19
    } as Object {
20
        class: "org.mule.module.netsuite.extension.api.CustomFieldList"
21
    }
22
} as Object {
23
    class: "org.mule.module.netsuite.extension.api.CustomRecord"
24
}


Use Case 3: Extend Above Dataweave Transformation to Add Field of Type RecordRef

We have field currency of type RecordRef in Employee record. It means the currency field is referring to the Currency record in NetSuite. So we need to map internalId to currency when creating Employee records.

We need to maintain the table or lookup which we will have a mapping between currency and internalId. Currently, we have placed the mapping between currency and internalId in the properties file.

Plain Text
 




x


 
1
netsuite.currency.internalId.USD=1
2
netsuite.currency.internalId.EUR=2
3
netsuite.currency.internalId.INR=3
4
 


Sr No External System Fields Data Type (External System) Netsuite Fields
( NetSuite Employee)
Data Type
(NetSuite Employee)
1 Currency string currency RecordRef

Dataweave for the above data mapping will look like as shown below and it will lookup internalId for currency in the properties file.

JSON
 




x
34
9





1
%dw 2.0
2
output application/java
3
---
4
payload map ( payload01 , indexOfPayload01 ) -> {
5
    currency: {
6
        internalId: Mule::p('netsuite.currency.internalId' ++ payload01.Currency default "USD")
7
        }
8
}


Final Dataweave for All the Three Use Cases

JSON
 




x





1
%dw 2.0
2
output application/java
3
---
4
payload map ( payload01 , indexOfPayload01 ) -> {
5
    externalId: payload01.Id default '',
6
    firstName: payload01.FirstName default '',
7
    middleName: payload01.MiddleName default '',
8
    lastName: payload01.lastName default '',
9
    isInactive: payload01.isInactive default false,
10
    mobilePhone: payload01.Mobile default '',
11
    title: payload01.Designation default '',
12
    currency: {
13
        internalId: Mule::p('netsuite.currency.internalId' ++ payload01.Currency default "USD")
14
        }
15
    customFieldList: {
16
        customField: [{
17
            scriptId: "custentity_multiemail",
18
            value: payload.Email default '',
19
        } as Object {
20
            class: "org.mule.module.netsuite.extension.api.StringCustomFieldRef"
21
        },
22
        {
23
            scriptId: "custentity_empsalary",
24
            value: payload.Salary default '',
25
        } as Object {
26
            class: "org.mule.module.netsuite.extension.api.StringCustomFieldRef"
27
        }
28
        ]
29
    } as Object {
30
        class: "org.mule.module.netsuite.extension.api.CustomFieldList"
31
    }
32
} as Object {
33
    class: "org.mule.module.netsuite.extension.api.CustomRecord"
34
}


Once you Add records in NetSuite, it will respond with internalId and that can be mapped with external system record.

JSON
 




x


 
1
[
2
  {
3
    "baseRef": {
4
      "externalId": "123weew12323223",
5
      "type": "EMPLOYEE",
6
      "internalId": "3941",
7
      "name": null
8
    },
9
    "status": {
10
      "statusDetail": [
11
        {
12
          "code": null,
13
          "message": null,
14
          "type": "ERROR",
15
          "afterSubmitFailed": false
16
        }
17
      ],
18
      "isSuccess": true
19
    }
20
  }
21
]


We can do a similar mapping for the update, upsert, and other operations in the NetSuite connector.

Now, you know how to use Add Record operation and data transformation with the MuleSoft NetSuite connector.

Database Data Types MuleSoft Strings Data mapping Data (computing) Use case

Opinions expressed by DZone contributors are their own.

Related

  • JSON-Based Serialized LOB Pattern
  • Projections/DTOs in Spring Data R2DBC
  • Build a Java Microservice With AuraDB Free
  • How to Store Text in PostgreSQL: Tips, Tricks, and Traps

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!