Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
75 views

Modified Java Script Value: Scenario of Calculating Age Using Date Function of Java Script

Uploaded by

Renato Santos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Modified Java Script Value: Scenario of Calculating Age Using Date Function of Java Script

Uploaded by

Renato Santos
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Modified Java Script Value

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:

1. Calculating Age using Date function of Java Script

2. Using String functions like: replace(), lower() and display the output using Alert() function.

Scenario of Calculating age using Date function of Java Script


We would be reading employee data from Data Grid step and calculate age from Date of birth. Then save it in
an excel file.

Building workflow
1. In process studio, create a new workflow and save it as shown in below images:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
2. Now we need to create employee data using “Data Grid” step. Drag & drop it in workspace area, double click
on this step to edit its properties as shown in the Tab-wise images below:

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:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
Click on Preview button to ensure about the data and format of the same.

Click on Close >> OK to complete the configuration.

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.

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
Now mention the parameters in “dateDiff()” function as explained below:
 Parameter1: “DOB” is the Input field coming from “Data Grid_EmployeeDetails” step.
 Parameter2: “CurrentDate” is the local variable created in script itself saving current date with the help of
“Date()” class.
 Parameter3: Write “y” to calculate the age in years.

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.

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
Click “OK” to complete the configuration.

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:

File & Sheet Tab:


 Specify a Filename with complete path where you want to save the output file.
 Select Extension from drop-down.

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
Content Tab:

 Mention Fields name as shown below by clicking on “Get Fields” button:

5. Save and Run the workflow. You can check output in Preview Data tab and also the excel output file as shown
below:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
© 2018 AutomationEdge Inc. All Rights Reserved.
This document is for your company’s internal use only and may not be distributed to any third party.
Scenario of using String functions of Java Script
We would be reading string data from Data Grid step and replace couple of words and change the text from
uppercase to lowercase.

Building workflow
1. In process studio, create a new workflow and save it as shown in below image:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
2. Now we need to create string data using “Data Grid” step. Drag & drop it in workspace area, double click on
this step to edit its properties as shown in the Tab-wise images below:

Meta tab:
 In Name column, enter field name
 In Type column, select data-type of the field.

Data tab:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
Click on Preview button to ensure about the data and format of the same.

Click on Close >> OK to complete the configuration.

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.

Now mention the parameters in “replace()” function as explained below:


 Parameter1: “Message” is the Input field coming from “Data Grid_StringInput” step.
 Parameter2: “WORLD” a text needs to be found.
 Parameter3: “FOLKS” a text needs to be replace with.

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)

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
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.

After this, to see the output, include “Alert()” function from “Special Function” category and pass the
parameter as “str1”.

Click “OK” to complete the configuration.

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
4. Save and Run the workflow. You can see output as shown in below images:

In first row, text is in lower case and the word “WORLD” has been change with “FOLKS” and “FUNCTION” has
been change with “PROGRAMME”.

Click on “OK” button.

In second row, text is in lower case and the word “FUNCTION” has been change with “PROGRAMME”.

Click on “OK” button.

Also you can check “Preview Data” tab for the output. Refer below image for the same:

© 2018 AutomationEdge Inc. All Rights Reserved.


This document is for your company’s internal use only and may not be distributed to any third party.
© 2018 AutomationEdge Inc. All Rights Reserved.
This document is for your company’s internal use only and may not be distributed to any third party.

You might also like