Modified Java Script Value: Scenario of Calculating Age Using Date Function of Java Script
Modified Java Script Value: Scenario of Calculating Age Using Date Function of Java Script
In this document we will see how to use “Modified Java Script Value” step to apply business logic in workflows.
This use case covers two examples as below:
2. Using String functions like: replace(), lower() and display the output using Alert() function.
Building workflow
1. In process studio, create a new workflow and save it as shown in below images:
Meta tab:
In Name column, enter fields name
In Type column, select data-type of the field.
In Format column, select format from drop-down if any, e.g.: DOB field is in “yyyy-MM-dd” format.
Data tab:
3. Next we need to calculate the age of all employees from DOB column. For this, drag & drop “Modified Java
Script Value” step from left pane. Connect it with the previous step “Data Grid_EmployeeDetails”.
Double-click on “Modified Java Script Value” step to write the script as shown in below images:
In left section “Java script functions:” >> Expand “Transform Functions” >> “Date Functions” and double-click
on dateDiff(var,var,var) function. It will automatically reflect in script or you can type as well.
Now click on “Get variables” button, so that the variables which we have created in the Java script are added
to the “Fields” section and they are available in workflow stream for further steps.
4. Now we want to save our output in an Excel file. Drag the step Microsoft Excel Writer in the working area and
connect it with the previous step (MJSV_CalculatingAge). Double click Microsoft Excel Writer step to edit its
properties as shown in below images:
5. Save and Run the workflow. You can check output in Preview Data tab and also the excel output file as shown
below:
Building workflow
1. In process studio, create a new workflow and save it as shown in below image:
Meta tab:
In Name column, enter field name
In Type column, select data-type of the field.
Data tab:
3. Next we need to replace “WORLD” with “FOLKS” and “FUNCTION” with “PROGRAMME” and convert
text form uppercase to lowercase. For this, drag & drop “Modified Java Script Value” step from left
pane. Connect it with the previous step “Data Grid_StringInput”. Double-click on “Modified Java
Script Value” step to write the script as shown in below images:
In left section “Java script functions:” >> Expand “Transform Functions” >> “String Functions” and double-
click on replace(var,var,var) and lower(var) functions accordingly. It will automatically reflect in script or you
can type also.
Note: you can mention n number of pairs for find-n-replace text. Like, we are using two pairs.
There is only one parameter in “lower()” function as “str1” (a string needs to be converted)
After this, to see the output, include “Alert()” function from “Special Function” category and pass the
parameter as “str1”.
In first row, text is in lower case and the word “WORLD” has been change with “FOLKS” and “FUNCTION” has
been change with “PROGRAMME”.
In second row, text is in lower case and the word “FUNCTION” has been change with “PROGRAMME”.
Also you can check “Preview Data” tab for the output. Refer below image for the same: