Assigning date or time to the variables

BPEL enables many date and time operations. In this recipe, we explore how to manage date and time in BPEL processes.

Getting ready

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>

How to do it…

In the BPEL process, we define the variables that accept date and time as shown in the following screenshot:

How to do it…

Next, add the assign activity, where we define the copy rules as follows:

  1. With the xp20:current-date() function, we assign the current date to the DateVar variable.
    <copy>
      <from expression = "xp20:current-date()"/>
      <to variable = "DateVar"/>
    </copy>
  2. With the xp20:current-time() function, we assign the current date to the TimeVar variable.
    <copy>
      <from expression = "xp20:current-time()"/>
      <to variable = "TimeVar"/>
    </copy>
  3. With the xp20:current-dateTime() function, we assign the current date to the DateTimeVar variable.
    <copy>
      <from expression = "xp20:current-dateTime()"/>
      <to variable = "DateTimeVar"/>
    </copy>
  4. With the 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>
  5. Now, we deploy the BPEL process, run an instance, and inspect the Audit Trail of the instance to see the various values assigned to the variables as shown in the following screenshot:
    How to do it…
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset