creating rules in process composer and using them in process · creating rules in process composer...

18
Creating Rules in Process Composer and using them in Process Applies to: SAP NetWeaver Composition Environment 7.1 EHP-1 Version. For more information, visit the Composition homepage. Summary This article deals with creating user defined rules set from process composer itself and then using them in the process. This also briefs up on creating decision table in rules set. The article expects the user to have undergone the tutorial End-To-End process implementation sample. Author: Srinivasan Subbiah Company: HCL Technologies Created on: 05 January 2009 Author Bio Srinivasan Subbiah is an Application Developer working in HCL Technologies Limited on SAP NetWeaver Technology (CAF, Web Dynpro for JAVA, Guided Procedures and BPM). SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 1

Upload: others

Post on 06-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Applies to: SAP NetWeaver Composition Environment 7.1 EHP-1 Version. For more information, visit the Composition homepage.

Summary This article deals with creating user defined rules set from process composer itself and then using them in the process. This also briefs up on creating decision table in rules set. The article expects the user to have undergone the tutorial End-To-End process implementation sample.

Author: Srinivasan Subbiah

Company: HCL Technologies

Created on: 05 January 2009

Author Bio Srinivasan Subbiah is an Application Developer working in HCL Technologies Limited on SAP NetWeaver Technology (CAF, Web Dynpro for JAVA, Guided Procedures and BPM).

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 1

Page 2: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Table of Contents Introduction .........................................................................................................................................................3 Editing the Web Dynpro Component ..................................................................................................................4 Creating the RuleSet ..........................................................................................................................................6

Creating a Decision Table...............................................................................................................................7 Editing the Process...........................................................................................................................................13 Testing the Application .....................................................................................................................................16 Related Content................................................................................................................................................17 Disclaimer and Liability Notice..........................................................................................................................18

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 2

Page 3: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Introduction After following the End-To-End process implementation, we will have a process with two human activities. First human activity will get the name and age. Second human activity will display them. We would have assigned User_A for first activity and User_B for the second one.

In this article, we will have one more variable namely ageStatus along with name and age in C_DisplayMyNameAge webdynpro component. Depending on the name and age, the ageStatus variable will be set and will be displayed in the Display Name Age human activity.

This will be achieved using the rule set, we will create in the process composer. The rule set will be consumed by a mapping activity. This mapping activity will be placed between the two previously created human activities.

The process diagram after following End-to-End process implementation article will look like the following figure.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 3

Page 4: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Editing the Web Dynpro Component We have to add a string variable to the interface controller, component controller of C_DisplayMyNameAge and have to edit the view for showing it.

Add the variable in the component controller and copy it to the interface controller as described in the specified article.

Go to the view’s context and create a variable and map it to that of component controller.

View Controller:

Go to view’s layout. Add a new text view element to the root element and bind it to the ageStatus attribute in the view’s context.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 4

Page 5: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Save the application and deploy it.

Go to Development Infrastructure perspective and select the process component dc_my_name_age. Right click on it and select Sync Used DCs.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 5

Page 6: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Creating the RuleSet Go to Process Composer perspective.

Navigate to dc_my_name_age Process Modelling Rules and Functions.

Right Click and select New RuleSet.

In the New RuleSet pop-up, enter the CheckNameAndAge for Name field. Leave the Return Type to be String. In Parameters, add two string variables namely name, ageStatus and an integer variable, age.

We will use the variables name and age in the condition. The result will be saved in the variable ageStatus. It should be noted that the data type of both ageStatus and Return Type are same.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 6

Page 7: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

CheckNameAndAge tab will open automatically. In the Result field, from the drop down, select ageStatus.

Here we are setting ageStatus as the return variable. The value in ageStatus will be returned to the process after executing the rule.

Creating a Decision Table

We will create a decision table. This decision table will check the name and age and accordingly will set the ageStatus variable. For simplicity, we will check if the name is “John” and the age is less than “20”, set ageStatus as “Teenage Boy”, else if age is greater than 20, set ageStatus as “Young Man”. If the name is “Julie” and age is less than “19”, set ageStatus as “Teenage Girl”, else if age is greater than 20 set ageStatus as “Young Lady”.

Go to Decision Tables, and click on New. Give a name in the Decision Table Name field and click on Next.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 7

Page 8: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Here for us the conditions we need to check are name and age. So from Available Conditions add name and age to the Selected Conditions. Click Next.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 8

Page 9: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Next we have to select the action. When a condition is satisfied this action will be executed. For us, this action should assign a string to the ageStatus as this will be returned back. So from Available Actions add ageStatus={String} to Selected Actions.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 9

Page 10: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Select Finish.

The decision table will be opened automatically. Now we have to enter the condition and action values.

Right click on Default Value under name and select Add Condition Values.

Enter the condition value for name. In our case, it will be “John”.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 10

Page 11: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Click ok. Delete the default value by right clicking it.

Similarly add the values for age and ageStatus and values for “Julie” also.

The final decision table will look like this.

For setting the ageStatus, we can fill a static string by just clicking on the cell and entering the value. Alternatively, we can also manipulate the values using Set Dynamic Value property which we will get by right clicking on the cell.

We have to create a rule. This rule will be called in the process and it will have to execute the decision table.

Select the Overview tab. Go to the Rules section. Create a new rule by clicking on New button. Enter the name of the rule as CheckNameAndAgeRule. The rule will open. Click on the add(+) button under If. Select Operation.isSuccessful() and double click on name in the options as shown below.

Then similarly select the value true and enter * there.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 11

Page 12: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Similarly select the add symbol under Then and select Evaluate Decision Table CheckNameAndAgeDecisionTable.

Finally the rule will look like this.

Thus we have created a rule which will be executed for any name entered.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 12

Page 13: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Editing the Process Now we will edit the process. We will add a mapping activity and a String Data Object for accommodating the ageStatus in the process context.

First we will create a Data Object. Select the Display Name Age human activity and from quick buttons select Artifacts. Enter a name for it.

Select String data type for the data object from Data Type tab.

Now we will create a Mapping activity. Delete the connection between the two human activities. Select Fill Name Age and create a mapping activity. Give a name to the mapping activity say RuleInvoker. Form a sequence connection from RuleInvoker mapping activity to the Display Name Age human activity.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 13

Page 14: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

The process diagram will look like this.

Select the RuleInvoker mapping activity and select Mapping tab. Drag FillMyNameAgeContext Name and FillMyNameAgeContext Age from left hand side to the AgeStatus in the right hand side.

Double click on the red marked icon for editing the function.

Remove the existing function. Select the rule set we created from Rules And Context demo.sap.com/dc_name_age CheckNameAndAge.

From the Context, drag and drop the name and age. The final expression will be like the following.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 14

Page 15: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Make sure to fill an empty string for ageStatus.

Click OK.

Select Display Name Age and do input mapping.

Save the application, build and deploy it.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 15

Page 16: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Testing the Application Start the process from NetWeaver administrator. Using the User_A’s account, log onto the portal. In his work items we can find FillMyNameAge activity. Open it and fill the details.

Using User_B’s account, log on to portal. Open the activity, DisplayMyNameAge. There we can see the output.

It can be seen that since name is John and age is 27, we are getting the statement “Young Man “. Similarly you can also test the other options also.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 16

Page 17: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

Related Content End-To-End process implementation

How to use Decision Tables in Rules Composer

Building a Composite Application from scratch-Part 3

For more information, visit the Composition homepage

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 17

Page 18: Creating Rules in Process Composer and using them in Process · Creating Rules in Process Composer and using them in Process . Applies to: SAP NetWeaver Composition Environment 7.1

Creating Rules in Process Composer and using them in Process

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com © 2008 SAP AG 18

Disclaimer and Liability Notice This document may discuss sample coding or other information that does not include SAP official interfaces and therefore is not supported by SAP. Changes made based on this information are not supported and can be overwritten during an upgrade.

SAP will not be held liable for any damages caused by using or misusing the information, code or methods suggested in this document, and anyone using these methods does so at his/her own risk.

SAP offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this technical article or code sample, including any liability resulting from incompatibility between the content within this document and the materials and services offered by SAP. You agree that you will not hold, or seek to hold, SAP responsible or liable with respect to the content of this document.