User Defined Java Class - SelfStudyDoc

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

User Defined Java Class

In this document we will see how to use “User Defined Java Class” step to apply business logic using Java code
in workflows. We will see very basic example i.e. how to add two numbers.

Scenario of adding two numbers using User Defined Java Class


We would be reading few pairs of numbers from Data Grid step and perform addition operation on them.

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 pair of few numbers using “Data Grid” step. Drag & drop it in workspace area, double
click on this step to edit its properties as shown in the 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.

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 perform the addition operation. For this, drag & drop “User Defined Java Class” step from
left pane. Connect it with the previous step “Data Grid Input”.
Double-click on “User Defined Java Class” step to write the code.

© 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.
When you double-click on “User Defined Java Class” step, it will look like below image:

4. Now we need to add a function called “processRow” which will act like a “main” function of Java code.
To add “processRow” function, go to left-side pane (Classes and code fragments), expand “Code Snippits” >>
“Common use” >> double-click on “Main”. It will add “processRow” function automatically in right-side
section as shown in below image:

5. In right-side “Class code” section, scroll-down till the end. Put the cursor just before the auto-generated code
as:
putRow(data.outputRowMeta, r);

Now in left-side, expand “Input fields” >> “Num1” >> double-click on “getNumber()”. Below code will add
automatically.
Double Num1 = get(Fields.In, "Num1").getNumber(r);
© 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.
Perform same operation for “Num2” as shown in below image:

6. Now create a method for adding “Num1” and “Num2” and call 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.
7. Now at the bottom, in “Fields” tab, add name of “Output field” as “AddResult” as shown in figure 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.
8. Click on “OK” and save your workflow. Again double-click on “User defined Java Class” step, you can notice
that, in left-side pane, expand “Output fields” and “AddResult” output field has been added here.
Expand “AddResult” >> double-click on “setValue()”, below code will be added automatically:

get(Fields.Out, "AddResult").setValue(r, value);

Refer below image for reference:

© 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.
Make some slight changes in code 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.
9. Now to print the output in “Logging” tab of process studio, add below code as shown in image:

logBasic("Addition is --->"+add);

Note: you can compare “logBasic()” function with “System.out.println()” function.

© 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.

10. Save and Run the workflow. You can check output in “Preview Data” tab and also in “Logging” tab 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.
Preview 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.
Logging 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.

You might also like