How to work with and format date values in Winshuttle Composer when working with SAP.
Within Composer, the date format shown on the Date Picker control is for display purposes only. What you see in the Date Picker is not the actual value sent to the SAP Web Service. Composer stores all dates in the format of YYYY-MM-DD to properly display dates in different locales. If you are working with SAP Web Services and a script that contains a date field, the formatting for the date needs to be modified by rules if it does not match the required SAP date format.
If SAP requires a different date format, a ‘helper date element’ needs to be created and added to the View to hold the user's date picker value. In addition, a rule will be added to this new field to format the SAP input field. The actual date SAP input field can then be removed from the view.
In addition, if a Date field is required, make sure that the Data Type of the Date field in the Transaction Script is a string. If the Date field is a Date data type within Transaction, there will be formatting problems with it after it is brought into the Composer form. Converting it to a string provides more control in the form so it can be more easily formatted to fit the needs of SAP.
A Purchase Order form contains a Date field, but the Date Format needs to be MM/DD/YYYY instead of the default yyyy-mm-dd. The following steps show you how to configure this in the form.
Setting the date field to a textbox
- Select the Date field within the field mapping for the SAP Web Service.
- Set the Element Type field to be TextBox.
- Delete this Element from the View.
Add and configure the new date picker
- Add a new Date Picker element to the form. This will be the field the end users fill in.
- Create a new Action Rule on the new Date Picker element.
- Set the Action to Set a Field Value
- Set the field to the Date Field that exists within the Web Service Mapping (the one converted to a text box under Setting the date field to a textbox.)
- In the Value property, select the f(x) option to configure a function.
- In the Insert Formula editor, click Insert Function
- Select the formatDate() function from the drop down
- The formatDate(dateString, pattern) function accepts two arguments. The first argument (dateString) is the value or xpath to the field that holds the value of the date inputted by the end user. The second argument (pattern) is the pattern of the date format needed for the SAP input. See fomatDate for a list of possible date patterns.
- For the first argument (dateString), select Insert Field Value to select the field created in step 3.
- For the second argument, insert the applicable date pattern. For this example the format of the date should be set to MM/DD/YYYY so the pattern entered will be “mm/dd/yyy”.
- Leave the Condition of the rule as the default (to run when field changes).
- Publish the solution. The date will be converted to the correct format.