0% found this document useful (0 votes)
10 views

MVEL Expression Language - Studio

Work essentials

Uploaded by

saketh reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

MVEL Expression Language - Studio

Work essentials

Uploaded by

saketh reddy
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 52

MVEL EXPRESSION LANGUAGE-STUDIO

MVEL Expression Language

Table of Contents
1 MVEL Expressions.............................................................................................................................. 5
1.1 Naming Conventions.......................................................................................................................... 5
1.2 MVEL Autocomplete:......................................................................................................................... 5
1.3 MVEL 2.x expressions....................................................................................................................... 6
2 Operators............................................................................................................................................. 8
2.1 Unary Operator:................................................................................................................................. 8
2.2 Comparison Operator......................................................................................................................... 8
2.3 Logical Operators............................................................................................................................. 10
2.4 Arithmetic Operators........................................................................................................................ 11
2.5 Other Operators............................................................................................................................... 12
3 Assignment........................................................................................................................................ 13
3.1 Literals:............................................................................................................................................ 13
3.2 Difference b/w Assignment and Equal............................................................................................. 14
4 Launch Parameter:............................................................................................................................ 15
4.1 Simple Type Parameter:.................................................................................................................. 15
4.2 Reference Type Parameter:............................................................................................................. 16
4.3 Convert Array Values to String......................................................................................................... 17
4.4 Date From Launch Parameter.......................................................................................................... 19
5 Integration Attributes:....................................................................................................................... 20
5.1 Simple Type Parameter:.................................................................................................................. 20
5.2 Reference Type Parameter:............................................................................................................. 20
5.3 Convert Array Values to String......................................................................................................... 20
6 Integration MAP........................................................................................................................... 22
7 Sequence Generator......................................................................................................................... 24
8 Da: Document Accessor(To retrieve Input File).............................................................................25
9 Evaluate Xpath: parts[].................................................................................................................. 26
9.1 Format Date..................................................................................................................................... 26
9.2 Format Number................................................................................................................................ 27
9.3 Right/Left Justification (Padding)..................................................................................................... 27
10 Mvel Functions.................................................................................................................................. 28
10.1 Substring....................................................................................................................................... 28
10.2 Index of......................................................................................................................................... 28
10.3 Substring-before........................................................................................................................... 29
10.4 Substring-after.............................................................................................................................. 29
10.5 Replace or Translate..................................................................................................................... 29
10.6 Contains........................................................................................................................................ 29
10.7 Normalize space:.......................................................................................................................... 29
10.8 Length:.......................................................................................................................................... 30
10.9 Concat.......................................................................................................................................... 30

2
MVEL Expression Language

10.10 Substring and Contains............................................................................................................. 30


10.11 Equal Ingnore Case:.................................................................................................................. 30
10.12 Aggregate Function................................................................................................................... 30
10.13 Lowercase................................................................................................................................. 31
10.14 UpperCase:............................................................................................................................... 31
10.15 Starts With................................................................................................................................. 31
10.16 Ends with................................................................................................................................... 31
10.17 Clear and remove...................................................................................................................... 32
10.18 Append...................................................................................................................................... 32
11 Control Flow: MVEL Expression Capabale Property:....................................................................33
11.1 if.................................................................................................................................................... 33
11.2 If else............................................................................................................................................ 33
11.3 else if............................................................................................................................................ 33
12 Ternary Operator:.............................................................................................................................. 34
12.1 Ternary statements:...................................................................................................................... 34
12.2 Nested Ternary Statements:......................................................................................................... 34
13 Hash Map and Array list................................................................................................................... 35
13.1 Hash Map..................................................................................................................................... 35
13.2 Array List to Hash Map................................................................................................................. 35
13.3 List to For Loop............................................................................................................................. 36
13.4 Remove Duplicates Using Array List............................................................................................37
13.5 CleanUp or remove Hash Map..................................................................................................... 37
14 MVEL Template Capabale Property on webservice.......................................................................39
14.1 Foreach-Statement Example on webservice................................................................................39
14.2 If-Statement Example on webservice............................................................................................ 39
15 Before and After Splitter................................................................................................................... 40
15.1 Last Row or Employee in Batch.................................................................................................... 40
15.2 To find total employees from input file..........................................................................................40
15.3 To find Success count on employee incase of inbound................................................................40
15.4 To find Error Count on employee incase of inbound.....................................................................40
15.5 Local-out condition Execute when................................................................................................ 41
15.6 In put message............................................................................................................................. 41
16 Studio Specific MVEL Expression Table......................................................................................... 42
17 USEFUL Links:.................................................................................................................................. 50

3
MVEL Expression Language

4
MVEL Expression Language

1 MVEL Expressions
MVEL is an incredibly powerful expression language which is tightly integration into the Workday ESB's Assembly
framework. With MVEL is it possible to construct powerful and flexible expressions for manipulating Assembly context
variables and associated Java objects, but as ever, with great power comes great responsibility!

1.1 Naming Conventions

A large number of properties are added to the mediation context by the ESB and some of the
shared components. Prefixing the properties you declare within your integration name will
making them easier to find when debugging the assembly and add a conceptual scope to the
properties. For example:
props['payforce.company.name']
If you set properties to contain the values of integration attributes, use "ia" as the prefix. For
example:
props['ia.include.job.code']
For Launch parameter : props['lp.include.job.code']
Always ensure that your property names are meaningful. Do not be tempted to abbreviate
property names. Descriptive and meaningful property names aid readability, and reduce the
overall cost of maintaining the code over subsequent revision.

1.2 MVEL Autocomplete:

Need help with the syntax of particular operations or with the names of
elements in your flow?, you can always access MVEL suggestions by
pressing Ctrl + Space Bar.

5
MVEL Expression Language

1.3 MVEL 2.x expressions may consist of:

 Property expressions

 Boolean expressions

 Method invocations

 Variable expression

 Function definitions

1.3.1 Property Expression


A utility adapter for gaining access to message properties using the
AssemblyUtils.PropertyMapAdapter class.

The following expression is equivalent to

context.getProperty('myProperty')

6
MVEL Expression Language

but less verbose:

props.myProperty

The following expression returns the property value set by a custom Spring bean:

Syntax for property: props['bean.property']

1.3.1.1 Multiple statements

You may write scripts with an arbitrary number of statements using the semi-colon to

denote the termination of a statement. This is required in all cases except in cases where

there is only one statement, or for the last statement in a script.

statement1; statement2; statement3

EG: props['user.name']= 'jeeva'; props['user.id']= '20558'; props['user.acc']= 'jthangaraj'

1.3.2 Variable Expression

Provides access to the MessageContextVariables interface as a Map. To access


variables, use the following notation:

Syntax:
vars['payroll.payee.in.extract']

props[‘user.name’] = vars['payroll.payee.in.extract']

7
MVEL Expression Language

2 Operators
2.1 Unary Operator:
2.1.1 new
Object instantiation or instance of class and allocating memory to the object.
props['p.ee.hash.map'] = new java.util.HashMap()

props['p.error.log'] = new java.lang.StringBuffer();

props['p.array.list'] = new java.util.ArrayList()

2.2 Comparison Operator


2.2.1 Equal: ==
Equality Check. Checks to see if the values on both sides of the operator are equal. Unlike Java, this is not an
identity check

Assigning props['count'] = 10; props['employee.count'] = 10

props['emp'] = props['count'] == props['employee.count']

EG: if props['count'] is equal to props['employee.count'], props['emp'] is true

10 == 10 then true

Result: props['emp'] = true

2.2.2 Not Equal: !=


Not Equals Check. Checks to see if the values on both sides of the operator are not equal.

Assigning props['count'] = 5; props['employee.count'] = 5

props['emp'] = props['count'] != props['employee.count']

EG: if props['count'] is not equal to props['employee.count'], props['emp'] is true

Result: 5 != 5 then false so props['emp'] = false

8
MVEL Expression Language

2.2.3 Greater Than : >


Greater Than Check. Checks to see if the value on the left side of the operator is greater than than value on the
right.
props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] > props['employee.count']

Result: props['emp'] = true

2.2.4 Less Than: <

Less Than Check. Checks to see if the value on the left side of the operator is less than value on the right.

props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] < props['employee.count']

Result: props['emp'] = false

2.2.5 Greater than or Equal to: >=


Greater Than or Equal. Checks to see if the value on the left hand side is greater than or equal to the value on the
right.
props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] >= props['employee.count']

Result: props['emp'] = true

2.2.6 Less than or Equal to: <=


Less Than or Equal. Checks to see if the value on the left hand side is less than or equal to the value on the
right.

props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] <= props['employee.count']

Result: props['emp'] = false

2.2.7 Contains
Value Containment Check. Checks to see if the value on the left contains the value on the right

9
MVEL Expression Language

props['count'] = 'Worker'; props['employee.count'] = 'Contingent Worker'

props['emp'] = props['count'] contains props['employee.count']

Result: props['emp'] = true. Since both property has value as Worker

2.3 Logical Operators


2.3.1 Logical And: And , &&
Logical AND. Checks to see that the values on both sides of the operator are true.

props['count'] && props['employee.count']

props['count'] and props['employee.count']

if(props['count'] == true && props['employee.count'] != true){ props['employee'] = 'Active' ;}

2.3.2 Logical OR : ||
Logical OR. Checks to see if either the value on the left or the right is true.

props['count'] || props['employee.count']

if(props['count'] == true || props['employee.count'] != true){ props['employee'] = 'Active' ;}

2.3.3 Chained OR : or
Chained OR. Checks a sequence of values for emptiness and returns the first non-empty value

props['count'] = 'Employee' props['employee.count'] = 'Contingent'

props['emp'] = props['count'] or props['employee.count']

Result: props['emp'] = 'Employee' since first property has value so it won’t check next property.

props['count'] = null props['employee.count'] = 'Contingent'

props['emp'] = props['count'] or props['employee.count']

Result: props['emp'] = 'Contingent' since first property is null So it checked next property and
returned it value.

10
MVEL Expression Language

2.4 Arithmetic Operators

2.4.1 Addition: +

props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] + props['employee.count']

Result: props['emp'] = 15

2.4.2 Subtraction: -

props['count'] = 10; props['employee.count'] = 5

props['emp'] = props['count'] - props['employee.count']

Result: props['emp'] = 5

2.4.3 Division: /

props['count'] = 4; props['employee.count'] = 2

props['emp'] = props['count'] / props['employee.count']

Result: props['emp'] = 2

2.4.4 Multiplication: *

props['count'] = 4; props['employee.count'] = 2

props['emp'] = props['count'] * props['employee.count']

Result: props['emp'] = 8

2.4.5 Modulus: %

props['count'] = 9; props['employee.count'] = 4

props['emp'] = props['count'] % props['employee.count']

Result: props['emp'] = 1 since reminder is 1

11
MVEL Expression Language

2.5 Other Operators


2.5.1 String Concatenation: +

String Concatenation. Overloaded operator for concatenating two strings together.

props['emp']="Contingent"; props['emp1']="Worker"

props['employee'] = props['emp'] + props['emp1']

Result: props[' employee '] = ContingentWorker

2.5.2 Numeric Concatenation: #

props['num'] = 12; props['num1'] = 56;

props['num.concat'] = props['num'] # props['num1']

Result: props['num.concat'] = 1256

2.5.3 Assignment: =
Assignment. Assigns the value on the right to the variable on the left.

props['num'] = 12

props['num'] = true

props['emp'] = 'employee' or props['emp'] = " employee"

props['emp'] = ''

12
MVEL Expression Language

3 Assignment

MVEL allows you assign variable in your expression, either for extraction from the runtime,
or for use inside the expression.

3.1 Literals:

A literal is used to represent a fixed-value in the source of a particular script.

3.1.1 Strings

Assigning Literals to property:

String literals may be denoted by single or double quotes.

"This is a string literal"

'This is also string literal'

props[‘user.name’] = 'This is also string literal'

Assigning xml Tags to properties:

props[‘user.name’] = '<hello>world</hello>'

props['employee_id_string'] = '<wd:Employee_Reference><wd:Integration_ID_Reference><wd:ID
wd:System_ID="WD-EMPLID">' + props['file_empid'] +
'</wd:ID></wd:Integration_ID_Reference></wd:Employee_Reference>'

props['get_worker_employee_id_string'] = '<wd:ID wd:type="Employee_ID">' + props['file_empid'] +


'</wd:ID>'

Assigning mimeType:

props[‘user.name’] = 'Hello World', 'text/xml'

3.1.2 Numerics

Assigning Numeric Value:

props['count'] = 0

props['count'] = 1+2

13
MVEL Expression Language

3.1.3 Boolean

Boolean literals are represented by the reserved keywords true and false.

Assigning Boolean value to property:

props['count'] = true

props['count'] = false

3.1.4 Null or nil

The null literal is denoted by the reserved keywords null or nil or '' or empty.

Assigning null value to property:

props['count'] = null

props['count'] = nil

props['count'] = ''

props['count'] = empty

3.2 Difference b/w Assignment and Equal


Difference b/w Assignment and Equal

Assignment: Here assigning or storing value for property

props['count'] = 0

props['count'] = empty

props['count'] = true

Equal: Here checking or testing this property is equal to that value or not

props['count'] == 0

props['count'] == empty

props['count'] == true

14
MVEL Expression Language

4 Launch Parameter:

Mvel helper class is lp: Provides access to the integration launch parameters. The lp variable
is only applicable to Workday internal server and integration Cloud developers.

4.1 Simple Type Parameter:

Mvel helper class for launch parameter is lp and to get data from simple type launch parameter need to use
getSimpleData('label') and here label should be your prompt name “Tax Frequency Value”.

Type lp. then press CNTRL + Space Bar then you will get all related methods.

EG: lp.getSimpleData('label')

props['lp.cc.wid']=lp.getSimpleData('Tax Frequency Value')

if we want to pass this below simple type prompt property value to Raas Report prompt
should convert it to string then you call this property to raas call to give input to your raas
report prompt.

props['lp.cc.wid']=lp.getSimpleData('Cost Centers')

props['get.cc.wid.prompt'] = props['lp.cc.wid'].toString()

15
MVEL Expression Language

Raas Report Mvel Property:

@{intsys.reportService.g
etExtrapath('costcenterpr
omptvaluegiven')}? 4.2 Reference Type Parameter:
Cost_Center!
WID=@{props['get.cc.wi Reference Type Parameter is nothing but prompt on your webservices fields.
d.prompt']} By clicking yellow arrow mark in the below screenshot you can access
webservice fields. There to find the fields directly you can select CRF(class
report fields) and you can type the fields on search bar or else you can take it
by expanding the webservice requests.

To use single instance reference type prompt value we need to use


getReferenceData('label', 'type') method.

props['lp.run.category'] = lp.getReferenceData('label', 'type')

Label is your prompt name(see above screenshot) : Run Category Type

Type can be: Reference ID or WID

16
MVEL Expression Language

props['lp.run.category'] =
lp.getReferenceData('Ru
n Category Type', 4.3 Convert Array Values to String
'Run_Category_ID')
To convert an array list to a string, the following can be used
(Array of Workers converted to a string to be used in a REST
or URL for RaaS):

props['lp.run.category'] =
lp.getReferenceData('Ru
n Category Type', ‘WID’)

When selecting multiple input in prompt.

To use Multi Instance reference type prompt value we need to use any one
of the below method

17
MVEL Expression Language

props['lp.cc.wid'] = lp.getWIDs('label')
or
props['lp.cc.wid'] = lp.getReferenceDataList('label', 'type')

To get the multiple values or list of values selected in Launch Parameter prompt use below
methods :

props['lp.cc.wid'] = lp.getWIDs('Cost Centers')

or

props['lp.cc.wid'] = lp.getReferenceDataList('Cost Centers', 'WID')

output: [6cb77610a8a543aea2d6bc10457e35d4, bc33aa3152ec42d4995f4791a106ed09,


80938777cac5440fab50d729f9634969, c4f78be1a8f14da0ab49ce1162348a5e]

Should convert this output format to following format which would be supported by raas report. To convert
as below should use below property.

6cb77610a8a543aea2d6bc10457e35d4!bc33aa3152ec42d4995f4791a106ed09!
80938777cac5440fab50d729f9634969!c4f78be1a8f14da0ab49ce1162348a5e

Convert Array Values to String

props['get.cc.wid.prompt']=props['lp.cc.wid']!=empty?
util.listToCommaDelimString(context.getProperty('lp.cc.wid')).replace(',','!') : null

should pass this property props['get.cc.wid.prompt'] to raas Report now. will now be a string of cost
center WIDs. The commas (,) are replaced by exlamation marks (!) as this is how you separate IDs in a
REST URL for Workday RaaS end points.
output: 6cb77610a8a543aea2d6bc10457e35d4!bc33aa3152ec42d4995f4791a106ed09!
80938777cac5440fab50d729f9634969!c4f78be1a8f14da0ab49ce1162348a5e

18
MVEL Expression Language

@{intsys.reportService.g
etExtrapath('costcenterpr
omptvaluegiven')}? In background input should go to raas report in below
Cost_Center! format:
WID=@{props['get.cc.wi
d.prompt']} customreport2/medtronic4/jthangaraj/MyCustomReport?
CostCenters!WID=6cb77610a8a543aea2d6bc10457e35d4!
bc33aa3152ec42d4995f4791a106ed09!
80938777cac5440fab50d729f9634969!
c4f78be1a8f14da0ab49ce1162348a5e

4.4 Date From Launch Parameter


4.4.1 To Find Current Effective Date:

props['date'] = lp.getDate('label')

props['date'] = lp.getDate('Current Effective Date and Time')

4.4.2 To Find Last Successful Date Time:

props['date'] = lp.getSimpleData('label')or props['date'] = lp.getDate('label')

props['lp.lastsuccessful.datetime']= lp.getSimpleData("Last Successful DateTime")

props['lp.lastsuccessful.date']=props['lp.lastsuccessful.datetime'].substring(0,10)

19
MVEL Expression Language

5 Integration Attributes:
Mvel helper class is intsys: Provides access to the integration system configuration for this assembly.

5.1 Simple Type Parameter:

To Access simple type integration attribute prompt, intsys.getAttribute('label') method should


be used.

Syntax: props['sftpEndPoint']=intsys.getAttribute('label')

props['sftpEndPoint']=intsys.getAttribute('SFTP Endpoint')

5.2 Reference Type Parameter:

To Access Reference type single instance integration attribute prompt,


intsys.getAttributeReferenceData('label', 'type')method should be used.

Syntax: props['pgp.key'] = intsys.getAttributeReferenceData('label', 'type')

props['pgp.key'] = intsys.getAttributeReferenceData('PGP Public Key', 'WID')

props['ia.run.category']=intsys.getAttributeReferenceData('RunCategoryType','Run_Category_ID')

or

props['ia.run.category']=intsys.getAttributeReferenceData('RunCategoryType','WID')

5.3 Convert Array Values to String

To convert an array list to a string, the following can be used (Array of Workers converted to a string to be
used in a REST URL for RaaS):

20
MVEL Expression Language

To Access Reference type multi instance integration attribute prompt,


intsys.getAttributeReferenceDataList ('label', 'type') or intsys.getWIDs('label') method should
be used.

props['ia.ledger.account.no.emp'] = intsys.getAttributeReferenceDataList('Ledger Account No


Employee Detail', 'WID')

props['ia.ledger.account.no.emp'] = intsys.getWIDs('Ledger Account No Employee Detail')

props['get.ledger.account.no.emp'] =props['ia.ledger.account.no.emp'] != empty ?


util.listToCommaDelimString(context.getProperty('ia.ledger.account.no.emp')).replace(',','|') : null

5.3.1 Report URL:


@{intsys.reportService.getExtrapath('costcenterpromptvaluegiven')}?ledger account!
WID=@{props['get.ledger.account.no.emp']}

5.3.2 How to get Integration Attribute or any MVEL Property to XSLT:


In XSLT or STX, first declare the "is" namespace in stylesheet: Then call the method from an
XPath expression

xmlns:is="java:com.workday.esb.intsys.xpath.ParsedIntegrationSystemFunctions"

is:getIntegrationAttributeValue('Entity Name')

(note the alternative mechanism for passing attribute values into XSLT in the next
paragraph):

props['ia.include.job.code'] = intsys.getAttribute('Include Job Code')

Declare a stylesheet parameter in the XSLT as follows:Label of above property should be


called in a global variable in xslt to call that mvel property to xslt as below.

<xsl:param name="ia.include.job.code" />

21
MVEL Expression Language

6 Integration MAP

To Retrieve External Value:

Syntax:

props['gender.type'] = intsys.integrationMapLookup('map_name', 'external_value')

simpleTextTypeMap

props['ia.simple.map'] = intsys.integrationMapLookup('simpleTextTypeMap', 'M')

enumTypeMap

props['ia.enum.map'] = intsys.integrationMapLookup('enumTypeMap', 'Active')

referenceTypeMap

props['ia.reference.map'] = intsys.integrationMapLookup('referenceTypeMap', 'Telephone')

To Retrieve Internal Value:

Syntax:

props['ia.label'] = intsys.integrationMapReverseLookup('map_name', 'key')

simpleTextTypeMap

props['ia.simple.map'] = intsys.integrationMapReverseLookup('simpleTextTypeMap', 'Male')

22
MVEL Expression Language

enumTypeMap

props['ia.enum.map'] = intsys.integrationMapReverseLookup('enumTypeMap', 1)

referenceTypeMap

props['ia.reference.map'] = intsys.integrationMapReverseLookup('referenceTypeMap', 'P')

How to access Integration Map in XSLT:

In XSLT or STX, first declare the "is" namespace in stylesheet: Then call the method from an XPath expression

xmlns:is="java:com.workday.esb.intsys.xpath.ParsedIntegrationSystemFunctions"

is:integrationMapReverseLookup('Earnings Code', 'EARNING_CODE')

is:getIntegrationMapValue('Time_Off_Codes','Time_Off_Type_ID')

(note the alternative mechanism for passing attribute values into XSLT in the next paragraph):

props['ia.simple.map'] = intsys.integrationMapLookup('simpleTextTypeMap', 'M')

S
Declare a stylesheet parameter in the XSLT as follows:

<xsl:param name="ia.simple.map" />

<xsl:value-of select="$ia.simple.map"></xsl:value-of>

23
MVEL Expression Language

7 Sequence Generator
which you can use to generate unique, sequenced file names. If your integration system needs to create a different
file name each time it runs, you can associate a sequence generator service with your Workday-in transport to
generate the file name. You define the service with one or more named sequencers in Studio, then configure the
sequencers in Workday.

props['lp.batch.id.seq'] = lp.getSequencedValue('label')

props['lp.batch.id.seq'] = lp.getSequencedValue('BatchIDSequence')

24
MVEL Expression Language

8 Da: Document Accessor(To retrieve Input File)


Within a Workday Studio integration, you can use the Document Accessor (da) variable
within an eval step's MVEL expression to access a document or input file from tenant or
some sftp server.

The following example gets a document from the Integration Event with filename
eib_transform_output.txt and adds is as a variable named var1:

da.toVar('eib_transform_output.txt', 'var1')
or

if (da.size() > 0 ) {da.toVar(0, "wd.retrieve.variable")}

25
MVEL Expression Language

9 Evaluate Xpath: parts[]


Parts[] : Provides array-based access to message parts using the MessageAdapter
interface. The root part is part 0, the first attachment is part 1.

For example, to get the content of first attachment, the root part:

parts[0].text

To get the content of the second attachment:

parts[1].text

Syntax: props['eval.xpath'] = parts[0].xpath('xpath')

props['eval.xpath']=parts[0].xpath('/env:Envelope/env:Body/wd:Get_Workers_Response/wd:Response_Data/
wd:Worker/wd:Worker_Data/wd:User_ID')

Syntax with namespace: props['myPropName'] = parts[0].xpath('xpath', 'namespaces')

props['namespace.row'] = 'wd http://workday.com'

props['row.employee.id'] = parts[0].xpath('payment_Offcycle/EMPLID',props['namespace.row'])

9.1 Format Date

To format a date using MVEL instead of XSLT, it can be done using the following example
(yyyy-MM-dd converted to MM/dd/yyyy):

props['p.input.date'] = '2013-10-03'

props['p.parsed.date'] = new java.text.SimpleDateFormat("yyyy-MM-dd").parse(props['p.input.date'])

props['p.date.formatted'] = new java.text.SimpleDateFormat("MM/dd/yyyy").format(props['p.parsed.date'])

26
MVEL Expression Language

9.2 Format Number

To format a number using MVEL instead of XSLT, it can be done using the following example
(##0.0000 converted to ##0.00):

props['p.employee.salary'] = parts[0].xpath("wd:Report_Entry/wd:Total_Annual_Base_Salary") /* let's say this is


1234.5678 */

props['p.parsed.number'] = new java.text.DecimalFormat("##0.00").parse(props['p.employee.salary'])

props['p.number.formatted'] = new java.text.DecimalFormat("##0.00").format(props['p.parsed.number'])

9.3 Right/Left Justification (Padding)

To justify, or pad, a value using MVEL the following can be used

org.apache.commons.lang.StringUtils.leftPad( '1234', 10,'0') /*(str inputValue, int size, str paddingChar) */

Output: 0000001234

org.apache.commons.lang.StringUtils.rightPad( '1234', 10,'0') /*(str inputValue, int size, str paddingChar) */

Output: 1234000000

27
MVEL Expression Language

10 Mvel Functions
10.1 Substring

Returns the substring from the start position to the specified length. Index of the first character is 1 here. If length is
omitted it returns the substring from the start position to the end

Example: substring('Beatles',1,4)
Result: 'Beat'
For String:

props['lastupddttm'] = 'Beatles'

props['lastupd_dt'] = props['lastupddttm'].toString().substring(1, 4)

Result: props['lastupd_dt'] = Beat

For Integer:

props['birth.date'] = lp.getDate('lp.mydate') which returns 2011-03-24-07:00

props['Birth.Date']=props['birth.date'].substring(0,10)

Result: props['Birth.Date'] = 2011-03-24

props['payment'] = parts[0].xpath("//Payment_Date").substring(2)

Result: parts[0].xpath("//Payment_Date") which returns 2014-03-30T00:00:00.000-07:00

props['payment'] = 14-03-30T00:00:00.000-07:00

10.2 Index of

Returns the positions within the sequence of items that are equal to the search item
argument. Index starts with 0 here.

Example: index-of ('12-10','-')

Result: 2

28
MVEL Expression Language

props['p.index.separator'] = parts[0].xpath("//Payment_Date").indexOf("-")

10.3 Substring-before
parts[0].xpath("//Payment_Date") returns 2014-03-30T00:00:00.000-07:00

props['p.index.separator'] = parts[0].xpath("//Payment_Date").indexOf("-")

Result: props['p.index.separator'] = 4 (Note: takes first hypen position )

props['p.substring.before']= parts[0].xpath("//Payment_Date").substring(0,props['p.index.separator']);

Result: 2014

10.4 Substring-after
props['p.index.separator'] = parts[0].xpath("//Payment_Date").indexOf("-")

props['p.substring.after']=parts[0].xpath("//
Payment_Date").substring(props['p.index.separator']+1);

10.5 Replace or Translate

props['Worker_Type'] = "Active_Worker"

props['Worker'] = props['Worker_Type'].toString().replace("_","Contingent ")

Result: props['Worker'] = ActiveContingentWorker

10.6 Replace all non-numeric characters


replace all non-numeric characters with a blank value

input: gray12345-2014.pdf

props['p'] = gray12345-2014.pdf

props['p.cleaned'] = props['p'].replaceAll('[^0-9]','')

output: 123452014

You could then substring the first 5 characters:

props['p.cleaned'].substring(0,5)

output: 12345

29
MVEL Expression Language

10.7 Contains
props['managerNotInWDError']=props['manager.errmessageback'].toString().contains('not a valid ID')

Example: Employee Id is not a valid id contains not a valid id string then returns true

10.8 Normalize space:

Removes leading and trailing spaces from the specified string, and replaces
all internal sequences of white space with one and returns the result. If
there is no string argument it does the same on the current node

props['row.plan.id']= parts[0].xpath("normalize-space(/record/PLAN_ID)")

Example:normalize-space(' The XML ')


Result: 'The XML'

10.9 Length:
props['EmployeeID'] = '20558'

props['emp.length'] = (props['EmployeeID'].length()

Result: props['emp.length'] = 5

10.10 Concat

concatenating two strings together.

props['lp.batch.id.seq']= lp.getSequencedValue('BatchIDSequence').toString().concat(props['Location'])

10.11 Substring and Contains


props['Period_end']=parts[0].xpath('substring(/rd:Report_Data/rd:Report_Entry/
rd:Pay_Group_Detail[contains(rd:Instance/@rd:Descriptor,"Bi-weekly")]/rd:End_Current_Period,1,10)')

10.12 Equal Ingnore Case:

30
MVEL Expression Language

parts[0].xpath("//Payment_Date") returns 2014

props['payment']=parts[0].xpath("//Payment_Date").equalsIgnoreCase('2014')

EG: 2014 equals 2014

Result: props['payment']= true (If it equals will return true otherwise false)

10.13 Aggregate Function


10.13.1 Sum
EG: Do sum salary of all the employees on xml message

props['total.taxes.paid.processed']= parts[0].xpath("sum(//Total_SOT_Processed)")

10.13.2 Count
EG: Do count the number of nodes

props['multiple.state.tax.election']=parts[0].xpath("count(/Worker_Tax_Election/State_Tax_Election)")
count with namespace used:

props['total_message_count_from_report']=
parts[0].xpath("count(Cost_Center_Data/Cost_Centers)",props['namespace.row'])

10.14 Lowercase

props['lowercas']=parts[0].xpath('/Off-cycle_Input_Data/Deduction_Reference/ID').toLowerCase()

EG: W_MED to w_med

10.15 UpperCase:

props['payment'] = parts[0].xpath("/Off-cycle_Input_Data/Deduction_Reference/ID ").toUpperCase()

EG: w_med to W_MED

31
MVEL Expression Language

10.16 Starts With

props['lowercas'] =parts[0].xpath('/Off-cycle_Input_Data/Deduction_Reference/ID').startsWith('prefix')

props['lowercas'] =parts[0].xpath('/Off-cycle_Input_Data/Deduction_Reference/ID').startsWith('W')

EG: Word starts with W (Condition satisfies then returns true or else returns false).

10.17 Ends with

props['lowercas'] =parts[0].xpath('/Off-cycle_Input_Data/Deduction_Reference/ID').endsWith('suffix')

props['lowercas'] =parts[0].xpath('/Off-cycle_Input_Data/Deduction_Reference/ID').endsWith('r')

EG: Colour ends with r (Condition satisfies then returns true or else returns false)

10.18 Clear and remove

props['ap.worker.past.map'].clear()

props['p.ee.hash.map'].remove(props['p.employee.id'])

10.19 Append
props['ap.page.worker.wids.sb'] = new java.lang.StringBuilder()

props['ap.page.worker.wids.sb'].append(props['p.employee.id']+', has a custom ID and will update with:,


'+props['p.file.custom.id']+'\r\n')

if(props['worker.hired.exists']==false){props['ap.page.worker.wids.sb'].append(props['current.worker.wid']).append(',') }

32
MVEL Expression Language

11 Control Flow: MVEL Expression Capabale Property:

11.1 if

Syntax: if(props['row.employee.id'] != props['last.employee.id']){/*do something here*/}

if(props['row.employee.id'] != props['last.employee.id']) { props['worker.offcycle.priority.out']


= 0; props['last.employee.id'] = props['row.employee.id']; }

11.2 If else
Syntax: if(props['p.is.boolean']){/*do something here*/}else]){/*do something here*/}

if(props['row.employee.id']!=props['last.employee.id']){props['worker.offcycle.priority.out']=0;}
else{props['worker.offcycle.priority.out']=empty;}

11.3 else if

Syntax:if(props['p.is.boolean']){/*dosomethinghere*/}elseif(props['row.employee.id']==props['last.employee.id']) {/*do
something here*/}else{/*do something here*/}

if(props['row.employee.id']!=props['last.employee.id'])
{ props['worker.offcycle.priority.out']=0;}elseif(props['row.employee.id']==props['last.employee.id'])
{props['worker.offcycle.priority.out']=1;}else{props['worker.offcycle.priority.out']=empty;}

33
MVEL Expression Language

12 Ternary Operator:
12.1 Ternary statements:

Ternary statement is similar to if else statement.

Syntax: props['worker_status'] = props['create_acct'] == 1 ? "Active" : "Inactive"

If props['create_acct'] == 1 then props['worker_status'] is Active otherwise Inactive

props['create_acct'] = props['report_acctid'] == '' ? true : false

props['worker_type'] = props['employee_Count'] == 1 ? 'Employee' : 'Contingent'

12.2 Nested Ternary Statements:

props['emp.row.count'] = props['count'] > 0 ? "Employee" : (props['count'] == 1 ? "Contingent" : "Worker")

if props['count'] > 0 it returns Employee otherwise it will check whether props['count'] == 1 returns Contingent
Otherwise returns Worker

34
MVEL Expression Language

13 Hash Map and Array list


13.1 Hash Map

Before Webservice or rass call and splitter:

props['p.ee.hash.map'] = new java.util.HashMap()

After Splitter put hashmap values

props['p.hash.key.value']=parts[0].xpath("wd:Report_Entry/wd:Employee_ID")

props['p.ee.hash.map'].put(props['p.hash.key.value'], parts[0].text)

After splitter Compare Input File with rass or websrvice call and get employee id:

props['p.employee.id']=parts[0].xpath("record/EmployeeID")

vars['p.ee.node']=props['p.ee.hash.map'].get(props['p.employee.id'])

if employee is found get custom id which is put along with employee id in hashmap

props['p.current.custom.id'] =if(vars['p.ee.node']!=empty){vars['p.ee.node'].xpath("wd:Report_Entry/wd:Custom_ID");}

13.2 Array List to Hash Map

Use this logic to convert an array into a single HashMap. In this example, we are just checking that a value exists in
the HashMap. A common use case is you only want to process employees who are in a certain organization defined
by an integration multi-value attribute. If the Map returns a '1' value, this translates to a the get() being successful

MVEL Expression Capabale Property:

1) Declare your HashMap

props['p.myHashMap']= new java.util.HashMap()

2) Get your Array list. In this case, it's a multi-value integration attribute

props['p.myAttributeList'] = intsys.getAttributeReferenceDataList('AttributeName', 'RefIDType')

35
MVEL Expression Language

3) Get the size of the Array list

props['p.myAttributesList.count'] = props['p.myAttributeList'].size()

4) Loop through the Array for each p.myAttributesList.count and put the list values in the HashMap

foreach(x : props['p.myAttributesList.count']){props['p.myHashMap'].put(props['p.myAttributeList'].get(x-1),'1')}

13.3 List to For Loop

Note:If we add or put our data to list or array list then only we can use for loop or for-each statement in mvel
expressions.

After Splitter and before aggregator:

list = context.getProperty('list');

props['id']=parts[0].xpath('/Put_Payroll_Off-cycle_Payment_Request/Payroll_Off-cycle_Payment_Data/Payment_ID')

list.add(props['id']); context.setProperty('list',list);

After aggregator

list = context.getProperty('list');

foreach(item:list) {System.out.println( item + ",")}

Another method for for loop

props['excluded-dce'] = false

int counter = props['excluded-dce-envs'].size()

foreach (x:counter) {if (props['dce-id'] == props['excluded-dce-envs'].get( x-1 )) {props['excluded-dce'] = true; }}

36
MVEL Expression Language

13.4 Remove Duplicates Using Array List

Before Webservice or rass call and splitter:

props['p.my.array.list'] = new java.util.ArrayList()

After Splitter put array list values

props['p.my.value']=parts[0].xpath("wd:Report_Entry/wd:Employee_ID")

if(!props['p.my.array.list'].contains(props['p.my.value'])) {props['p.my.array.list'].add(props['p.my.value']); }

13.5 Add and Contains Combination in Array List


props['p.array.list'] = new java.util.ArrayList()

props['p.array.list'].add(/*your directory key*/)

When you need to check if the data exists, you can do the following which returns a boolean:

props['p.array.list'].contains(/*directory key from file*/)

13.6 CleanUp or remove Hash Map

37
MVEL Expression Language

Before Webservice or rass call and splitter:

props['p.ee.hash.map'] = new java.util.HashMap()

After Splitter put hashmap values

props['p.hash.key.value']=parts[0].xpath("wd:Report_Entry/wd:Employee_ID")

props['p.ee.hash.map'].put(props['p.hash.key.value'], parts[0].text)

Before Webservice or rass call and splitter:

props['p.remaining.keys'] = props['p.ee.hash.map'].keySet()

After Splitter get hashmap values

props['p.employee.id']=parts[0].xpath("record/EmployeeID")

vars['p.ee.node']=props['p.ee.hash.map'].get(props['p.employee.id'])

props['p.ee.hash.map'].remove(props['p.employee.id'])

38
MVEL Expression Language

14 MVEL Template Capabale Property on webservice


14.1 Foreach-Statement Example on webservice

For Loop on xml message or webservice message on write component


To loop through an array or list you can use the following where props['p.remaining.keys'] is a list value
Note:If we add or put our data to list or array list then only we can use for loop or for-each statement in mvel
expressions.

MVEL Template Capabale Property:

<root>
@foreach{props['p.remaining.keys'] as id}
<ee>@{id}</ee>
@end{}
</root>

14.2 If-Statement Example on webservice

MVEL Template Capabale Property:

If condition on xml message or webservice message on write component

<root>
@if{props['p.is.boolean']}
<ee>*Do Something Here*</ee>
@end{}
</root>

If statement Example on webservice

<wd:Workday_Account_for_Worker_Update
xmlns:wd="urn:com.workday/bsvc"
wd:version="v21.1">
<wd:Worker_Reference>
@{props['employee_id_string']}
</wd:Worker_Reference>
<wd:Workday_Account_for_Worker_Data>
@if{(props['worker_status'] == 'Inactive' && props['company_reference_id'] == 'MNA' &&
props['ia_allow_inactive_accounts'] == true) || (props['worker_status'] == 'Active' && props['company_reference_id'] ==
'MNA') || (props['worker_status'] == 'Inactive' && props['ia_allow_inactive_accounts'] == true)}
<wd:Account_Disabled>true</wd:Account_Disabled>
@end{}
@if{props['worker_status'] == 'Active' && props['company_reference_id'] != 'MNA'}
<wd:Account_Disabled>false</wd:Account_Disabled>
@end{}
</wd:Worker_Reference>
</wd:Workday_Account_for_Worker_Update>
</env:Body>
</env:Envelope>

39
MVEL Expression Language

15 Before and After Splitter


15.1 Last Row or Employee in Batch

How to find Last Employee in a batch after Splitter


props['last.row.to.process'] = util.isLastMessageInBatch()

15.2 To find total employees from input file


Initialize variable before splitter:

props['total.count'] =0

After Splitter

props['total.count'] = props['total.count'] + 1

or another method to find total employees from input file

props['total.count']=parts[0].xpath("count(/Worker_Tax_Election/State_Tax_Election)")

15.3 To find Success count on employee incase of inbound


Initialize variable before splitter:

props['prop.success.count']=0

After Loading data to webservice

props['prop.success.count'] = props['prop.success.count'] + 1

15.4 To find Error Count on employee incase of inbound


Initialize variable before splitter:

props['prop.error.count'] =0

After handling send error component where we use our webservice request

props['prop.error.count'] = props['prop.error.count'] + 1

or another method to find error employees

props['prop.error.count'] = props['total.count'] - props['prop.success.count']

40
MVEL Expression Language

15.5 Local-out condition Execute when

props['prop.percentage.change'] == true

15.6 In put message

props['prop.current.percentage']+'% complete.'

41
MVEL Expression Language

16 Studio Specific MVEL Expression Table

Varia
Description Usage examples
ble

con Provides access to the The following expression gets the value of the property
tex MediationContext object, myProperty on the MediationContext:
t which is the main context
object used to pass information context.getProperty('myProperty')
around in assemblies. This
class contains various objects
used to store and pass the data
between the assembly
components, including:

 MediationMessage

 variables

 properties

 error and error-related


flags

 assembly audit

 customer id

 dynamic endpoint

da Within a Workday Studio The following example gets a document from the
integration, you can use the Integration Event with filename
Document Accessor (da) eib_transform_output.txt and adds is as a
variable within an eval step's variable named var1:
MVEL expression to access a
document. da.toVar('eib_transform_output.txt', 'var1')

env Provides access to the JVM The following example returns the cc.hostname
system properties. environment property set as -Dcc.hostname on the
command line:

env['cc.hostname']

42
MVEL Expression Language

Varia
Description Usage examples
ble

epg Provides access to the The following MVEL expressions return various results
wd.external.paygroupsMediati from calls to the Get_External_Paygroups Web
onContext property, which service:
contains the result of a call to
the  epg.isSet() == true
Get_External_Paygroups
Web service operation. The  epg.getExternalPayGroups('descriptor'
epg variable is only applicable )
to Workday internal server and
integration Cloud developers.
 epg.getExternalPayGroupWID('descripto
r')

 epg.getStartDate('periodWid')

 epg.getStartDate('payGroupWid,
'periodWid')

 epg.getEndDate('periodWid')

 epg.getEndDate('payGroupWid,
'periodWid')

 epg.getPaymentDate('periodWid')

 epg.getPaymentDate('payGroupWid',
'periodWid')

 epg.getWIDForStartDate('date')

 epg.getWIDForStartDate('payGroupWid',
'date')

 epg.getWIDForEndDate('date')

 epg.getWIDForEndDate('payGroupWid',
'date')

 epg.getWIDForPaymentDate('date')

 epg.getWIDForPaymentDate('payGroupWid
', 'date')

 epg.getCurrentPeriod('date')

43
MVEL Expression Language

Varia
Description Usage examples
ble

 epg.getCurrentPeriod('payGroupWid',
'date')

 epg.getPreviousPeriod('date')

 epg.getPreviousPeriod('payGroupWid',
'date')

 epg.getNextPeriodReference()

 epg.getNextPeriodReference('payGroupW
id')

ftp Returns the result of an ftp list The following MVEL expressions return true:
operation. The ftp variable is
bound to an instance of the  ftp.isSftp('sftp://
MVELFTPHelper utility class. It myserver.somewhere.com/myDirectory')
can be used to test URI
protocol schemes used to  ftp.isExplicitSSL('ftpse:/
represent FTP, SFTP, FTPS, myserver.somewhere.com/myDirectory')
FTPSE (FTPS with explicit
mode SSL), and FTPSI (FTPS
with implicit mode SSL).

Currently the Workday Network


only supports FTPS with
implicit mode.

int Provides access to the The following expression accesses an integration


sys integration system attribute named username:
configuration for this assembly.
intsys.getAttribute('username')
Note: The workday-in
transport calls the
Get_Integration_Systems
Web service operation
transparently to get integration
attribute and map settings and
populates the wd.int.sys
property using the intsys
MVEL variable. If you use
intsys convenience methods
such as intsys.name, which
returns the integration system

44
MVEL Expression Language

Varia
Description Usage examples
ble

name, you must first define


services on the workday-in
that define attributes and maps
for the integration system.
Using intsys to access an
attribute at runtime will causes
a failure unless a service is
defined on the integration
system. For more details, see
“Defining and Configuring
the Attribute Map Service
for an Integration”.

lp Provides access to the The following MVEL expressions return various results
integration launch parameters. from the Launch_Integration_Event_Data Web
The lp variable is only service operation, where the label value is the
applicable to Workday internal wd:Parameter_Name value or its wd:Label value:
server and integration Cloud
developers. The  lp.getUserName()
implementation class for this
variable is:
 lp.getUserNameWID()
com.workday.integration.launch.L
aunchParametersHelper  lp.getIntegrationEventWID()

Before using the lp MVEL  lp.getIntegrationSystemRefWID()


variable, you need to assign
the launch parameters XML to  lp.isSet() == true, which is true if the
the variable called wd.launchparameters property contains an
wd.launchparameters. XML document in the correct format.
When an integration receives
its launch parameters from the  lp.getParameterData('label'), which
OMS in the form of the
returns the
wd:Launch_Integration_E
Integration_Runtime_Parameter_Data
vent_Data element, it can
element for the given parameter.
assign the XML context to the
wd.launchparameters
variable. An integration can  lp.exists('label') == true, which is true if
also construct the a parameter with the given label exists.
wd:Launch_Integration_E
vent_Data XML message in  lp.getSimpleData('label'), which only
the case of an externally applies to parameters of simple type, such as
launched integration such as string, date, or number.
Payforce.
 lp.getDate('label'), which returns an

45
MVEL Expression Language

Varia
Description Usage examples
ble

xsd:date value as a string. This only applies to


parameters of simple type, such as string, date,
or number. Time portions are excluded if the
underlying data value includes them.

 lp.getMap('label'), which is used for


parameters that have multiple values with
Instance_Set_Reference elements. The
properties object contains all the IDs for each
instance.

 lp.getWIDs('label'), which is used for


parameters that have multiple values with
Instance_Set_Reference elements.

 lp.getDescriptor('label', 'wid'), which


is used for parameters that have multiple values
with Instance_Set_Reference elements. It
returns the wd:Descriptor attribute associated
with the instance with the given WID.

mes Provides access to the The following expression gets the root part of the
sag MediationMessage interface. message as text from the MediationMessage interface:
e
message.rootPartAsText

mta Provides access to the The following expression sets data in an MTable:
ble MTableAdapter interface,
which defines the operations on mtable['my_property'].set(0, 'Data_Column', 'my_test_data')
an MTable instance, where
MTable is an in-memory table The following expression gets data from an MTable:
of data.
mtable['my_property'].get(0, 'Data_Column')

par Provides array-based access to For example, to get the content of part 0, the root part:
ts message parts using the
MessageAdapter interface. parts[0].text
The root part is part 0, the first
attachment is part 1. To get the content of the first attachment:

parts[1].text

46
MVEL Expression Language

Varia
Description Usage examples
ble

To get the header someHeader from the root part:

parts[0].getHeader('someHeader')

To get the MIME type of the root part:

parts[0].mimeType

To get the content of the root part as a DOMSource:

parts[0].getAs(DOMSource)

To get the content of the root part as a String:

parts[0].getAs(String)

To get the string content of the XPath expression /a/b:

parts[0].xpath('/a/b')

or the equivalent with namespace overrides:

parts[0].xpath('/xx:a/xx:b', 'xx http://www.somewhere.com')

Note: By default, the Workday server runtime takes all


XML prefix-to-namespace mappings for XPath
expressions from the assembly.xml file, inspecting all
of the XML elements in the file. Specify namespaces
within the xpath method only to override the
declarations in the file. This default behavior applies to
MVEL expressions that use the MessageAdapter
interface only.

To evaluate an XPath Boolean expression, you use the


xpathB method.

parts[0].xpathB('/a/b')

This evaluates whether the node /a/b exists in the


document. This method is also overloaded to support a
second namespace parameter.

The xpathF method returns the result of the XPath


query as a string containing the XML fragment

47
MVEL Expression Language

Varia
Description Usage examples
ble

representing the node list of the results. An empty string


is returned if the XPath expression does not produce any
matches.

parts[0].xpathF('/a/b')

This method is also overloaded to support a second


namespace parameter.

You can also use set accessors for text, headers, and
MIME types, for example:

parts[0].setText('Here is some new content')


parts[0].setMimeType('text/xml')
parts[0].setAs('Here is some new content')
parts[0].setHeader('SomeHeader', 'SomeValue');

pro A utility adapter for gaining The following expression is equivalent to


ps access to message properties
using the context.getProperty('myProperty')
AssemblyUtils.PropertyM
apAdapter class. See the but less verbose:
warning message below this
table for property name issues. props.myProperty

The following expression returns the property value set


by a custom Spring bean:

props['bean.property']

spr Provides access to the Spring The following expression gets the name attribute of the
ing context for the WSAR using the bean called Fred in the Spring context:
ApplicationContext interface.
spring.getBean('fred').name

uti Provides access to utilities for You can use the following expression in conjunction with
l working with MVEL the splitter component to check whether the current
expressions. The util variable message in the MediationContext is the last message
is bound to an instance of the that the splitter will generate:
MVELUtilHelper utility class,
which provides handy functions props['is.last.record'] =
for use within MVEL
expressions such as time and

48
MVEL Expression Language

Varia
Description Usage examples
ble

date manipulation and XML


testing. Workday currently util.isLastMessageInBatch()
provides over 40 utility
functions that you can access To ensure that an assembly component produces well-
using the util variable. For formed XML, use the cleanString(String) function,
more details, see the Javadoc for example, within a write step's text element,:
for each utility function.
&lt;ns:Message_Summary>@{util.cleanString(props['is.messag
e.summary'])}&lt;/ns:Message_Summary>

var Provides access to the For example, to get the text of the variable myVariable:
s MessageContextVariables
interface as a Map. To access vars['myVariable'].text
variables, use the following
notation: To determine if a variable is defined:
vars['myVariable'] vars['myVariable'] != null

To get the MIME type associated with a variable:

vars['myVariable'].mimeType

To get the string value of node /a/b using XPath:

vars['myVariable'].xpath('/a/b')

or the equivalent with namespace support:

vars['myVariable'].xpath('/xx:a/xx:b', 'xx
http://www.somewhere.com')

To evaluate an XPath Boolean expression, you use the


xpathB method:

vars['myVariable'].xpathB('/a/b')

This evaluates whether the node /a/b exists in the


document. This method is also overloaded to support a
second namespace parameter:

vars['myVariable'].xpathF('/a/b')

This returns a string containing the XML fragment for a


node-list that matches /a/b zero or more times. This
method is also overloaded to support a second

49
MVEL Expression Language

Varia
Description Usage examples
ble

namespace parameter.

xml Returns the result of the The following expression checks whether there are
dif xmldiff step as a Java object differences between the two documents:
f of type XMLDiffStepResult,
xmldiff.isDifferent() == true
which is also available as a
property called
For more examples of the xmldiff MVEL variable
wd.xmldiff.step.result in the
usage, see “Sample MVEL Usage”.
MediationContext.

For Loop in mvel:

props['Workers']=lp.getReferenceDataList( 'mySelectedWorkers', 'Employee_ID')

<?xml version="1.0" encoding="UTF-8"?>

<wd:Get_Workers_Request xmlns:wd="urn:com.workday/bsvc" wd:version="v22.1">

<wd:Request_References wd:Skip_Non_Existing_Instances="true">

@foreach{props['Workers'] as emp}

<wd:Worker_Reference>

<wd:ID wd:type="Employee_ID">@{emp}</wd:ID>

</wd:Worker_Reference>

@end{}

</wd:Request_References>

</wd:Get_Workers_Request>

50
MVEL Expression Language

If condition for webservice in wstester

<root>

@if{props['p.is.boolean']}

<ee>*Do Something Here*</ee>

@elseif{props['p.numeric.value'] == 1}

<ee>*Do Something Else*</ee>

@else{}

<ee>*Else*</ee>

@end{}

</root>

51
MVEL Expression Language

17 USEFUL Links:

http://mvel.codehaus.org/Home

http://www.mulesoft.org/documentation/display/current/Mule+Fundamentals

http://mulesoft.github.io/mule-module-mvel/usage.html#mvel-fundamentals

http://www.w3schools.com/xpath/xpath_nodes.asp

52

You might also like