Presentation is loading. Please wait.

Presentation is loading. Please wait.

Www.regoconsulting.comPhone: 1-888-813-0444 The Power of GEL Scripting to Enhance Functionality Hidden Automation.

Similar presentations

Presentation on theme: "Www.regoconsulting.comPhone: 1-888-813-0444 The Power of GEL Scripting to Enhance Functionality Hidden Automation."— Presentation transcript:

1 www.regoconsulting.comPhone: 1-888-813-0444 The Power of GEL Scripting to Enhance Functionality Hidden Automation

2 www.regoconsulting.comPhone: 1-888-813-0444 2 ● Background of GEL ● Basic Script Structure ● Commonly Used Tags ● Hands on exercises with creating GEL Scripts ● Best Practices ● Real-life Examples ● Q&A Topics

3 www.regoconsulting.comPhone: 1-888-813-0444 3 ● GEL (Generic Execution Language) is a tool you can use to turn XML into executable code. It is based on Jelly, a Commons project. It has been extended and embedded into CA Clarity PPM to enable custom logic to solve business problems. ● Additional information can be found in the CA Documentation (CAClarityPPM_XOG_DeveloperGuide_ENU.pdf) and at the Apache Jelly website at Background of GEL

4 www.regoconsulting.comPhone: 1-888-813-0444 4 ● The GEL run-time is packaged with XOG in the XOG client. Once the client is installed, you can use the GEL command in the bin directory of the XOG client to validate and execute GEL scripts. ● GEL can also be used within Clarity processes. GEL Setup

5 www.regoconsulting.comPhone: 1-888-813-0444 5 Script Structure Header Comment Footer

6 www.regoconsulting.comPhone: 1-888-813-0444 6 A GEL script is an executable XML file that is built from qualified elements bound to Java code called tags. Using namespace declarations, tags are organized into tag libraries which are made available in a script. Hello World Example: Hello World ${i}! ● Note: An entire script always resides within the GEL script tag. GEL Tags

7 www.regoconsulting.comPhone: 1-888-813-0444 7 xmlns:core="jelly:core" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" xmlns:sql="jelly:sql" xmlns:xog=" xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary" xmlns:soapenv="" xmlns:file="jelly:com.niku.union.gel.FileTagLibrary" xmlns:util="jelly:util" xmlns:email="jelly:email" xmlns:ftp="jelly:com.niku.union.gel.FTPTagLibrary" Common Namespaces

8 www.regoconsulting.comPhone: 1-888-813-0444 8 Variables are used extensively throughout GEL scripts. Many tags can set variables. An example of a tag that can set variables is core:set. You can use the common syntax ${variable_name} to reference variables. In the Hello World example, 'i' is a variable which is set by the forEach tag and is incremented with each loop. Hello World Example: Hello World ${i}! Variables

9 www.regoconsulting.comPhone: 1-888-813-0444 9 ● Conditionals / Loops ● Variables / Parameters ● Database Operations ● Logging ● Exception ● SOAP / XOG ● File Operations ● Email Commonly Used Tags

10 www.regoconsulting.comPhone: 1-888-813-0444 10 ● … ● … … Conditionals / Loops

11 www.regoconsulting.comPhone: 1-888-813-0444 11 ● … ● … ● Note that there are two separate forEach loop types. The core version performs basic FOR looping. If you need to retrieve values from an XML document to use in the loop condition (that is, need to use a SELECT clause), then you need the GEL implementation. Conditionals / Loops cont.

12 www.regoconsulting.comPhone: 1-888-813-0444 12 ● This tag allows values to be passed into a GEL script from a CA Clarity PPM process. Inside the GEL script, you can refer to the parameter as you would any other variable (that is, using the ${variablename} syntax). The optional attribute secure="true" causes CA Clarity PPM to hide the actual value in the user interface with asterisks (*). Variables

13 www.regoconsulting.comPhone: 1-888-813-0444 13 ● This tag is used to set basic variables; that is, ones that do not need to be extracted from an XML document. Refer to the variable using the ${variablename} syntax. ${yes} You can do some basic math on the variable: ${yes+2} ● Use this tag when it is necessary to extract the value of the variable from an XML document. This tag differs from the tag in that it takes a select attribute which in turn requires an XPath statement. If you are unfamiliar with XPath, think of it as a hierarchy mapping of the XML document. In the example below, the select statement points the way to the Statistics node of a XOG output file. Variables cont.

14 www.regoconsulting.comPhone: 1-888-813-0444 14 ● This tag allows you to set variables with a scope that extends beyond the current script. ● The tag is used to create an XML document in memory. This is how you will build XOG requests. The tag can be used to generate an entire XML document, or specific nodes that can later be attached into an existing XML document. Variables cont.

15 www.regoconsulting.comPhone: 1-888-813-0444 15 Custom Action GEL scripts associated with processes have the following parameters available to them: ● Object instance ID If no object is associated with the process, the ID is -1. Otherwise the ${gel_objectInstanceId} parameter contains the object instance ID. ● Process ID ${gel_processId} is the process identifier; all instances of this process share this identifier. ● Process instance ID ${gel_processInstanceId} is the process instance identifier; all instances have a unique value. ● All built-in parameters have a "gel_" prefix and are of data type - numeric. Built-in Parameters

16 www.regoconsulting.comPhone: 1-888-813-0444 16 Information contained within GEL tags is case sensitive. For example, if you declare a variable as follows: PRJ-123456 Then reference the variable as follows: ${v_projectid} This will not output PRJ-123456. However, this will not cause an actual error to occur, so you can’t “catch” this error. Case Sensitive Issues

17 www.regoconsulting.comPhone: 1-888-813-0444 17 ● Datasources ● SQL Queries ● SQL Updates ● SQL Bind Variables / Parameters ● Transactions Database Operations

18 www.regoconsulting.comPhone: 1-888-813-0444 18 There are a couple of methods you can use within GEL to connect to your Clarity database. The recommended method is to use: The tag takes the database id attribute as follows: The above tag takes the connection properties (including password) from Clarity’s properties (set in the CSA). Niku, in the above example, is the ID of the default internal Clarity database. If you create additional external database definitions, you can reference them in the same manner. For example, if you added a second database connection definition called “ORA-FIN” you could reference it as follows: Datasources

19 www.regoconsulting.comPhone: 1-888-813-0444 19 Note that the var attribute is optional. If you do not specify a variable, the tag uses the default, and all subsequent SQL calls will use the same default. For example, you can do: SELECT 1 from dual OR SELECT 1 from dual Datasources cont.

20 www.regoconsulting.comPhone: 1-888-813-0444 20 Reasons to use the tag ● You are unable to add the database connection to the CSA ● You need to connect to a DB that isn’t Oracle or SQL Server ● You want to run the script from the command line and don’t have a copy of the properties.xml file on your computer Note: The above example allows you to have more than one datasource defined, and to specify which datasource to use through the “clarityDS” variable. Datasources cont.

21 www.regoconsulting.comPhone: 1-888-813-0444 21 The following is an example of a simple SQL query called from within a GEL script This query returns data in an array (for all intents and purposes) with the name “result.” Note: Due to the nature of XML, using certain characters (‘ ’) within your query would cause an error without enclosing the query in the CDATA tag. Because of this, it is a best practice to include this tag in all queries. SQL Query

22 www.regoconsulting.comPhone: 1-888-813-0444 22 You can then access the data in the “result” array using the tag. There are a couple of different ways to do this: Resource Name: ${row[0]} Resource Name: ${row.resName} Note: When possible, avoid setting a bunch of variables with the results of the query. SQL Query cont.

23 www.regoconsulting.comPhone: 1-888-813-0444 23 Often times processes require updating the values of specific attributes. One of the ways to do this is with a SQL Update statement. Keep in mind the following when performing direct database updates ● Generally speaking, it is best to avoid Insert statements – these are best suited for XOG ● Direct database updates will not trigger a process to start – XOG updates typically will trigger processes to start ● Avoid updating OOTB tables when possible – using XOG will ensure all Clarity business rules are followed ● It is generally safe to update custom attributes with a SQL update. These are typically found in tables beginning with odf_ca ● Extra caution should also be used within On-demand environments SQL Update

24 www.regoconsulting.comPhone: 1-888-813-0444 24 Example The variable ${updateCnt} will contain the number of rows that the update statement affects Note: Using CDATA tags in update statements is also preferred. SQL Update cont.

25 www.regoconsulting.comPhone: 1-888-813-0444 25 Many times SQL statements will include variables that are passed in to the statement. It is best to set these up as parameters within the SQL Statement. This serves a couple of purposes: ● Ensures data types are correct ● Prevents SQL injection ● Allows reuse of SQL statements for performance gains Example: Note: You must have a tag for each ? in the SQL statement, even if they are using the same value. The parameters also must be placed in the order that they appear in the statement. SQL Bind Variables / Parameters

26 www.regoconsulting.comPhone: 1-888-813-0444 26 ● Very Useful if you need your updates to be “All or Nothing” COMMIT ROLLBACK SQL Transaction

27 www.regoconsulting.comPhone: 1-888-813-0444 27 ● Use this tag to insert status messages into the process engine log table ● Very useful when debugging scripts ● Avoid using too many logging statements, as it can impact performance ● Different levels of logging – INFO, WARN, ERROR This is an example log message. Logging Messages

28 www.regoconsulting.comPhone: 1-888-813-0444 28 Use the GEL fault-handling tags to catch exceptions and exit gracefully when a process failure occurs. Use the tag to capture exceptions into a variable. Outside of the catch tags, you can check the variable and write it to the console. Example: Exception: ${sqlException} Exceptions

29 www.regoconsulting.comPhone: 1-888-813-0444 29 Clarity Environment: Username: regou Password: Clarity123 Note: When creating processes, please distinguish your process from others by using your name in the process name and id Example: Hands On Exercises

30 www.regoconsulting.comPhone: 1-888-813-0444 30 ● URLs are not set up correctly in the properties.xml file. This means that if you need to reference the URL, you’ll have to hard-code it. Example: ● Caching Issues Limitations to Rego U Environment

31 www.regoconsulting.comPhone: 1-888-813-0444 31 Create a process that uses a GEL script to update the following fields on the project object: Approved By (rego_appr_by): Resource that started the process Approval Date (rego_appr_date): Today’s Date Note: Environment is an Oracle environment Approved By field uses the Resource Browse lookup ( Exercise #1

32 www.regoconsulting.comPhone: 1-888-813-0444 32 SQL to update project fields: UPDATE odf_ca_project ocp SET ocp.rego_appr_date = sysdate, ocp.rego_appr_by = (SELECT FROM bpm_run_processes brp JOIN srm_resources r ON brp.initiated_by = r.user_id WHERE = ?) WHERE = ? Exercise #1 Hint

33 www.regoconsulting.comPhone: 1-888-813-0444 33 Exercise #1 Review

34 www.regoconsulting.comPhone: 1-888-813-0444 34 By including the SOAP and XOG namespaces in GEL scripts, you give GEL the ability to communicate with the XOG web service. You must package each invocation in a proper SOAP envelope. The following steps must be used within a GEL script to communicate with the XOG web service: ● Include the proper namespaces ● Obtain a session ID ● Create the XML file to send ● Execute the XOG ● Parse the Results ● Logout SOAP / XOG

35 www.regoconsulting.comPhone: 1-888-813-0444 35 XOG - Include the proper namespaces

36 www.regoconsulting.comPhone: 1-888-813-0444 36 Unable to obtain a Session ID. XOG - Obtain a Session ID

37 www.regoconsulting.comPhone: 1-888-813-0444 37 Example: XOG - Create the XML File

38 www.regoconsulting.comPhone: 1-888-813-0444 38 ${sessionID} XOG - Execute the XOG

39 www.regoconsulting.comPhone: 1-888-813-0444 39 User XOG Stats: ${xogStats} XOG - Parse the Results

40 www.regoconsulting.comPhone: 1-888-813-0444 40 ${sessionID} XOG - Logout

41 www.regoconsulting.comPhone: 1-888-813-0444 41 Create a process that can be initiated from a custom object for a Project Request that will XOG in a new project Exercise #2 Create project using the Name and ID of the Project Request

42 www.regoconsulting.comPhone: 1-888-813-0444 42 Sample Project XOG: SQL to get Project Request Name and ID: SELECT pr.code prjCode, prjName FROM odf_ca_rego_prj_req pr WHERE = ? Exercise #2 Hint

43 www.regoconsulting.comPhone: 1-888-813-0444 43 Exercise #2 Review

44 www.regoconsulting.comPhone: 1-888-813-0444 44 GEL can open a file (and if it is an XML file or a comma-delimited file, parse out all the nodes and attributes), read the file, and write to it. It can also perform FTP operations on files. It cannot, however, create a directory to put files in, move files around, or delete files after it is done with them. File Operations

45 www.regoconsulting.comPhone: 1-888-813-0444 45 Resource Last Name: ${row[0]} Resource First Name: ${row[1]} File Operations – Read File

46 www.regoconsulting.comPhone: 1-888-813-0444 46 File Operations – Write File

47 www.regoconsulting.comPhone: 1-888-813-0444 47 GEL scripts are often used to send emails. Using a GEL script notification allows for a lot more flexibility than sending an action item. There are two types of email tags, and. It is recommended to use the tag where possible. Email

48 www.regoconsulting.comPhone: 1-888-813-0444 48 ● Email server information is derived from the properties.xml of the installation. ● Supports HTML Example: Email cont.

49 www.regoconsulting.comPhone: 1-888-813-0444 49 ● Mail Server must be specified within the tag ● Does not support HTML ● Supports Attachments Example: App-ca.log File Email cont.

50 www.regoconsulting.comPhone: 1-888-813-0444 50 Write a script that will email a list of all active projects with managers that are not active users in Clarity to the resources within the following group: Exercise #3

51 www.regoconsulting.comPhone: 1-888-813-0444 51 SQL to get Resources in Group: SELECT r.first_name || ' ' || r.last_name resName, resEmail FROM cmn_sec_user_groups ug JOIN cmn_sec_groups g ON ug.group_id = AND g.group_code = 'regou_gel_script' JOIN srm_resources r ON r.user_id = ug.user_id SQL to get Projects: SELECT prjId, i.code prjCode, prjName, r.full_name prjMgr FROM inv_investments i JOIN inv_projects ip ON ip.prid = AND ip.is_template = 0 AND ip.is_program = 0 AND (i.purge_flag = 0 OR i.purge_flag IS NULL) JOIN odf_ca_project ocp ON = JOIN cmn_sec_users u ON i.manager_id = AND u.user_status_id != 200 JOIN srm_resources r ON = r.user_id Send Emails from the following email address: Exercise #3 Hint

52 www.regoconsulting.comPhone: 1-888-813-0444 52 Exercise #3 Review

53 www.regoconsulting.comPhone: 1-888-813-0444 53 ● If a variable can be changed by an admin, or stores a password, use the tag instead of ● Comment your code ● Properly format and indent your code ● Place all code within the tags, even comments ● Avoid excessive logging, but keep enough for debugging purposes ● When possible, pull server info from properties file on server Example: Best Practices

54 www.regoconsulting.comPhone: 1-888-813-0444 54 ● Integrations with HR ● Integrations with Financial systems ● Timesheet Notifications ● Updating Resource Rights ● What have you used GEL scripts for? Real Life Examples

55 www.regoconsulting.comPhone: 1-888-813-0444 55 Questions Contact US 888.813.0444 Email Contact Web Site

Download ppt "Www.regoconsulting.comPhone: 1-888-813-0444 The Power of GEL Scripting to Enhance Functionality Hidden Automation."

Similar presentations

Ads by Google