BPEL enables many date and time operations. In this recipe, we explore how to manage date and time in BPEL processes.
We create an empty synchronous BPEL process (DateTime.bpel
) and adjust the request message to accept date and time. In DateTime.xsd
, we modify the process element as follows:
<element name = "process"> <complexType> <sequence> <element name = "input" type="dateTime"/> </sequence> </complexType> </element>
In the BPEL process, we define the variables that accept date and time as shown in the following screenshot:
Next, add the assign activity, where we define the copy rules as follows:
xp20:current-date()
function, we assign the current date to the DateVar
variable.<copy> <from expression = "xp20:current-date()"/> <to variable = "DateVar"/> </copy>
xp20:current-time()
function, we assign the current date to the TimeVar
variable.<copy> <from expression = "xp20:current-time()"/> <to variable = "TimeVar"/> </copy>
xp20:current-dateTime()
function, we assign the current date to the DateTimeVar
variable.<copy> <from expression = "xp20:current-dateTime()"/> <to variable = "DateTimeVar"/> </copy>
xp20:format-dateTime
function, we format the current date to the FormatDate
variable and assign it to the response variable.<copy> <from expression = "xp20:format-dateTime(bpws:getVariableData('FormatDate'), '[D01]/[M01]/[Y0001]')"/> <to variable = "FormatDate"/> </copy> <copy> <from variable = "FormatDate"/> <to variable = "outputVariable" part = "payload" query = "/client:processResponse/client:result"/> </copy>