9
Mule-DataWeave with flowref lookup

Mule data weave with flowref lookup

Embed Size (px)

Citation preview

Page 1: Mule data weave with flowref lookup

Mule-DataWeave with flowref lookup

Page 2: Mule data weave with flowref lookup

2

Connect with Salesforce

At times, you may find that you need to connect one or more of your

organization's on-premise systems with a SaaS application such as

Salesforce. Ideally, these independent systems would talk to each other

and share data to enable automation of end-to-end business processes.

Use Mule applications to facilitate communication between your on-prem

system(s) and Salesforce. (Though this use case does not extend as far,

you can also use Mule to facilitate communication between SaaS

providers.)

Page 3: Mule data weave with flowref lookup

3

DataWeave and FlowRefLookup

Beyond transforming and mapping data from one format to another, you can use an Anypoint DataWeave Transformer to access other flows in a Mule application to acquire additional information. Use a flow lookup to acquire information outside the message, then append it to the payload.

Page 4: Mule data weave with flowref lookup

4

Steps

Log in to your Salesforce account, then navigate to the Setup tab. Now click on Customize -> Accounts -> Fieldsunder the Build section on the left side of the page.

Now click on New under the Account Custom Fields & Relationships section.In Step 1 of the new field process, select Text, then click Next to continue.In Step 2, enter values for your new field as per the table below, then click Next to continue.

In Step 4, check the Account Layout box, then click Save.Your new field name appears followed by a double-underscore and a lowercase "c": Region__c This is the new field to which DataWeave will map the region data it acquires from another flow.

Page 5: Mule data weave with flowref lookup

5

Steps

Open the Example project in Anypoint Studio from Anypoint Exchange. Do not run the application.Log in to your Salesforce account. From your account menu (your account is labeled with your name), select Setup.In the left navigation bar, under the Personal Setup heading, click to expand the My Personal Information folder.Click Reset My Security Token. Salesforce resets the token and emails you the new one.Access the email that Salesforce sent and copy the new token onto your local clipboard.In your SaaS Integration application in Mule Studio, click the Global Elements tab.Double-click the Salesforce global element to open its Global Element Properties panel. In the Security Token field, paste the new Salesforce token you copied from the email. Alternatively, configure the global element in the XML Editor.Change the contents of the Username and Password fields to your account-specific values, then click OK to save your changes.

Page 6: Mule data weave with flowref lookup

6

CreateNewSalesforceAccountFlow

The File Endpoint polls the input folder for new files every ten seconds. When it spots a new file, it reads it and passes the content to the Anypoint DataWeave transformer. This transformer not only converts the format of the data from CSV to a collection, it automatically maps the input fields from the CSV file – company_name, company_address, etc. – to output fields that Salesforce uses in a collection.The DataWeave also utilizes a flow lookup. Flow lookup accesses another flow in the application to acquire the sales region for each new account. DataWeave invokes the LookupSalesRegionFlow which uses the company_state data to determine into which sales region the account falls. DataWeave then maps this newly acquired data to the custom field in Salesforce, Region__c.

Page 7: Mule data weave with flowref lookup

7

LookupSalesRegionFlow

This flow consists of a Groovy component and a Logger. The script in the component uses state information in the message payload to calculate the sales region to which the account belongs. Invoked by the flow lookup in DataWeave, this flow exists only to determine a sales region for each account in the CSV file.

Page 8: Mule data weave with flowref lookup

8

Flow

Page 9: Mule data weave with flowref lookup