Clarity

Expand all | Collapse all

Gel Scripts in Processes

Anon Anon05-21-2014 05:09 AM

  • 1.  Gel Scripts in Processes

    Posted 05-21-2014 01:14 AM

    Hi,

    I am new to Gel Scripting. I had gone through the gel.zip file and learnt a lot from that.

    I want to know how do we embed gel scripts in processes. I mean, can somebody share some examples which would work in processes.

    I have tried basic examples via xog client, like Hello World, loops, variables, etc.

    Thanks



  • 2.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:09 AM
      |   view attached

    "...I want to know how do we embed gel scripts in processes..."

    You add the GEL script as a "Custom Script" in the "Action" section of the step in a process;

     



  • 3.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:15 AM

    Thanks Dave for sharing the screenshot. I knew these things.

    I am not able to figure out what gel script should I run. Because gel:out is not showing any output.

    So please share basic example that I can run and see the working of the gel script.



  • 4.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:30 AM

    gel:out will not send output to the Clarity application, it sends outout to stdout (e.g. when you run the GEL from a command-line using the local install XOG-client).

    If you want to see "output" in the Clarity application, use gel:log (instead of gel:out) and then you see the "messages" in the process instance execution within Clarity (click the little message flag to see them alongside the "BPM-0546: Custom script has completed." message)
     



  • 5.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:33 AM

    Thanks for the information.

    Could you suggest what other gel scripts should I practice in the process to get started with ?



  • 6.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:39 AM

    and which primary object should I choose ?



  • 7.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:47 AM
    vijit:

    and which primary object should I choose ?


    ...for a GEL script that is not related to a specific object instance, then you don't choose any object.

    ...if your process is to be related to an object instance (eg run this process for this project), then you choose that object (eg project) and then the "Id" of the object is available to you within the GEL script as a variable.
     



  • 8.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:43 AM

    There are some simple examples in the "GEL - Why helloworld is useful" document in the gel.zip file that you say you already have.  Just change the gel:out to gel:log in them if you are running them in the application.
     



  • 9.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:48 AM

    What else can I practice apart from the helloworld document.

    I tried using database operations but, it gives am error. Do we have to make a connection in application too??

     what primary object should I choose to run db operations and how can I see the results.?



  • 10.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:57 AM

    Read the "Basic guide to getting started with GEL" document from that gel.zip file, that has examples of database connections and manipulating data (via XOG) - these are the things that I would typically be doing in a GEL script.
     



  • 11.  RE: Gel Scripts in Processes

    Posted 05-21-2014 06:13 AM

    how do I invoke the process for which I have not set the primary object?

     



  • 12.  RE: Gel Scripts in Processes

    Posted 05-21-2014 06:36 AM

    Run the "Execute a Process" job, it takes the process name as a parameter.
     



  • 13.  RE: Gel Scripts in Processes

    Posted 05-21-2014 06:47 AM

    After running the job , where to see the output?

     



  • 14.  RE: Gel Scripts in Processes

    Posted 05-21-2014 06:54 AM

    Under Processes in the admin menu - on the Initiated processes tab.
     



  • 15.  RE: Gel Scripts in Processes

    Posted 05-21-2014 07:59 AM

    Thanks a lot Dave for helping me out.!

    One more question , when I run sql queries in he application itself, do I need to make a connection?

    Where can I see the results of the select statement which I have used in the Gel Script.

     

     



  • 16.  RE: Gel Scripts in Processes

    Posted 05-21-2014 08:21 AM

    If you read the documents that I have pointed you at, you will see examples where the GEL script makes a connection to the database itself within the GEL script - it can either reference the database that the Clarity application is running under, or you can sepcify any other database that you can access (but you need to specify the driver connection explictly then in the GEL - there are examples in that document again on how you would do this).

    As for the "output" from any SQL you run in GEL, it depends on what YOU do with that SQL statement in the GEL script - at the point that you run the SQL inside GEL then the SQL results are just in variables 'accessible' to GEL, you can dump these out to a log file (gel:out / gel:log / file:write etc) but its entirely up to what you code it to do.
     



  • 17.  RE: Gel Scripts in Processes

    Posted 05-22-2014 01:46 AM

    I tried this gel script in a process:

    <gel:script xmlns:core="jelly:core"
    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    xmlns:sql="jelly:sql">

    <gel:setDataSource dbId="Niku"/>
    <sql:query var="result">
         select name, unique_name from srm_projects
                </sql:query>
    </gel:script>

     

    the script ran successfully, but I could;nt figure out how to see the result. Please help with the code.

     

    Thanks



  • 18.  RE: Gel Scripts in Processes

    Posted 05-22-2014 02:54 AM

    to be specific how to get the output in a file?

    i went through the manual but the code is not working for me.



  • 19.  RE: Gel Scripts in Processes

    Posted 05-22-2014 04:11 AM

    Be clear, I am NOT going to write some code for you - you have to pay me (or at least the company that I work for) money to do your job for you!

    However, I am happy to tell you where to find your answers though, and I think I have done this several times and perhaps you are just not realising that?

    --

    The little GEL script you posted above with the SQL statement in it, all that does is put the contents of the SQL query into the variable you have specified - "result".  You need to extract the data from that variable in order to do something with it....

    ...and all this is explained (with an exampe) in the "Basic guide to getting started with GEL" document that I have already pointed you at, on page 9, in the section called "Example, simple query" - the looping of the results set (the "foreach" bit) is reading the SQL results from the "result" set and outputting the results on the stdout - if you used that code and changed the gel:out to gel:log (like I suggest above) then you would see the results in the initiated processes messages in the application (also as explained above).

    You are now talking about outputting to a file - examples on how to do this can be found in the other document in the gel.zip file "GEL for Dummies" on page 17 in the "File Operations" section.

    --

    There are no easy answers to how to do stuff in GEL, you have to think of it as a programming language and if you want to do anything you have to code it to do that - the best advice you will get is by looking at other examples (like in those documents, or on these message boards) and then you coding your own GEL based on those examples.
     



  • 20.  RE: Gel Scripts in Processes

    Posted 05-22-2014 05:10 AM

    Thanks a lot Dave for explaining the process in detail.

    I didn't mean that you should write a code for me.

    I tried the gel:log tag and was able to see the output in the message log. But the file output is giving me an error , that's why I asked again for file.

     

     



  • 21.  RE: Gel Scripts in Processes

    Posted 05-22-2014 05:17 AM

    Thats OK - just read the "File Operations" bit now!  smiley

    (Note that file locations are relative to where the GEL is running, so if you are specfying something on a C drive, then this is the C drive of the Clarity BG server that is running your process and NOT your local C drive)



  • 22.  RE: Gel Scripts in Processes

    Posted 05-22-2014 06:53 AM

    I ran this script but I am getting error. Please suggest how to resolve it:

    <gel:script xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
         xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
         xmlns:sql="jelly:sql"
         xmlns:xog="http://www.niku.com/xog"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

     <gel:parameter default="http://nikuvm:80" var="XOGURL"/>
     <gel:parameter default="svong" var="XOGUsername"/>
     <gel:parameter default="svong" secure="true" var="XOGPassword"/>


     <!-- Log into XOG and get a session ID -->
     <soap:invoke endpoint="${XOGURL}/niku/xog" var="auth">
      <soap:message>
       <soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xog="http://www.niku.com/xog">
        <soapenv:Header/>
        <soapenv:Body>
         <xog:Login>
          <xog:Username>${XOGUsername}</xog:Username>
          <xog:Password>${XOGPassword}</xog:Password>
         </xog:Login>
        </soapenv:Body>
       </soapenv:Envelope>
      </soap:message>
     </soap:invoke>

     <!-- Checking whether a sessionID is returned.  If not, it means that Login was unsuccessful -->
     <gel:set asString="true" select="$auth/SOAP-ENV:Envelope/SOAP-ENV:Body/xog:SessionID/text()" var="sessionID"/>
     <core:choose>
      <core:when test="${sessionID == null}">
       <gel:log>Couldn't Log in.  Check the username/password.</gel:log>
      </core:when>
      <core:otherwise></core:otherwise>
     </core:choose>

     <!--Run XOG and attach an input file...alternatively the Body section can be the NikuDatabus section of an input file-->
     <soap:invoke endpoint="${XOGURL}/niku/xog" var="runresult">
      <soap:message>
       <soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xog="http://www.niku.com/xog">
        <soapenv:Header>
         <xog:Auth>
          <xog:SessionID>${sessionID}</xog:SessionID>
         </xog:Auth>
        </soapenv:Header>
        <soapenv:Body>
         <gel:parse var="xmlindoc" file="C:\Clarity\XOG\xml\rsm_resources_read.xml"/>
         <gel:include select="$xmlindoc"/>
        </soapenv:Body>
       </soapenv:Envelope>
      </soap:message>
     </soap:invoke>


    <!-- Read the output and extract some information from it -->
     <gel:set asString="true" select="$runresult/SOAP-ENV:Envelope/SOAP-ENV:Body/NikuDataBus/XOGOutput/Status/@state"
    var="XOGoutcome"/>
     <core:switch on="${XOGoutcome}">
      <core:case value="SUCCESS">
       <gel:forEach select="$runresult/SOAP-ENV:Envelope/SOAP-ENV:Body/NikuDataBus/Resources/Resource"
    var="outputnode">
        <gel:log><gel:expr select="$outputnode/PersonalInformation/@displayName"/></gel:log>
       </gel:forEach>
       <gel:set asString="false" select="$runresult/SOAP-ENV:Envelope/SOAP-ENV:Body/NikuDataBus/XOGOutput/Statistics" var="stats"/>
       <gel:log>Success!  Total number of records: <gel:expr select="$stats/@totalNumberOfRecords"/></gel:log>
      </core:case>
      <core:case value="FAILURE">
       <gel:set asString="false" select="$runresult/SOAP-ENV:Envelope/SOAP-ENV:Body/NikuDataBus/XOGOutput/Statistics" var="stats"/>
       <gel:log>XOG failed.  Out of <gel:expr select="$stats/@totalNumberOfRecords"/> records, <gel:expr select="$stats/@failureRecords"/> failed.</gel:log>
      </core:case>
      <core:default>
       <gel:log>Couldn't find XOG output summary.  Please check the output file manually.</gel:log>
      </core:default>
     </core:switch>


     <!-- Log out of the XOG -->
     <soap:invoke endpoint="${XOGURL}/niku/xog" var="logoutresult">
      <soap:message>
       <soapenv:Envelope  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xog="http://www.niku.com/xog">
        <soapenv:Header>
         <xog:Auth>
          <xog:SessionID>${sessionID}</xog:SessionID>
         </xog:Auth>
        </soapenv:Header>
        <soapenv:Body>
         <xog:Logout/>
        </soapenv:Body>
       </soapenv:Envelope>
      </soap:message>
     </soap:invoke>

    </gel:script>

     

    Error:

    BPM-0704: An error occurred while executing custom script: org.apache.commons.jelly.JellyTagException: null:52:82: <gel:parse> C:\Clarity\XOG\xml\rsm_resources_read.xml (The system cannot find the path specified) at com.niku.union.gel.tags.ParseTag.doTag(ParseTag.java:86) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at org.apache.commons.jelly.impl.StaticTag.doTag(StaticTag.java:65) at org.apache.commons.jelly.impl.StaticTagScript.run(StaticTagScript.java:102) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at org.apache.commons.jelly.impl.StaticTag.doTag(StaticTag.java:65) at org.apache.commons.jelly.impl.StaticTagScript.run(StaticTagScript.java:102) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at com.niku.union.gel.tags.soap.SOAPTagSupport.parseBody(SOAPTagSupport.java:68) at com.niku.union.gel.tags.soap.MessageTag.doTag(MessageTag.java:38) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at com.niku.union.gel.tags.soap.InvokeTag.doTag(InvokeTag.java:65) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at com.niku.union.gel.tags.ScriptTag.doTag(ScriptTag.java:20) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247) at com.niku.union.gel.GELScript.run(GELScript.java:48) at com.niku.union.gel.GELController.invoke(GELController.java:74) at com.niku.bpm.services.ExecuteCustomAction.run(ExecuteCustomAction.java:207) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:724) Caused by: java.io.FileNotFoundException: C:\Clarity\XOG\xml\rsm_resources_read.xml (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at java.io.FileInputStream.<init>(FileInputStream.java:101) at com.niku.union.gel.tags.ParseTag.doTag(ParseTag.java:68) ... 28 more Root cause java.io.FileNotFoundException: C:\Clarity\XOG\xml\rsm_resources_read.xml (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:146) at java.io.FileInputStream.<init>(FileInputStream.java:101) at com.niku.union.gel.tags.ParseTag.doTag(ParseTag.java:68) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at org.apache.commons.jelly.impl.StaticTag.doTag(StaticTag.java:65) at org.apache.commons.jelly.impl.StaticTagScript.run(StaticTagScript.java:102) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at org.apache.commons.jelly.impl.StaticTag.doTag(StaticTag.java:65) at org.apache.commons.jelly.impl.StaticTagScript.run(StaticTagScript.java:102) at org.apache.commons.jelly.impl.ScriptBlock.run(ScriptBlock.java:95) at org.apache.commons.jelly.TagSupport.invokeBody(TagSupport.java:186) at com.niku.union.gel.tags.soap.SOAPTagSupport.parseBody(SOAPTagSupport.java:68) at com.niku.union.gel.tags.soap.MessageTag.doTag(MessageTag.java:38) at org.apache.commons.jelly.impl.TagScript.run(TagScript.java:247)...



  • 23.  RE: Gel Scripts in Processes

    Posted 05-22-2014 07:16 AM

    Does C:\Clarity\XOG\xml\rsm_resources_read.xml exist on the BG server that you are running on?
     



  • 24.  RE: Gel Scripts in Processes

    Posted 05-22-2014 07:51 AM

    I have it in C:\Program Files\CA\Clarity\CA Clarity PPM XOG\xml\rsm_resources_read.xml.

    Which is exactly the background server?



  • 25.  RE: Gel Scripts in Processes

    Posted 05-22-2014 07:59 AM

    You code is saying "pick up the file from C:\Clarity\XOG\xml\rsm_resources_read.xml" - that is why its failing.

    You have the file on C:\Program Files\CA\Clarity\CA Clarity PPM XOG\xml\rsm_resources_read.xml so I don't understand why you are even confused about why it could not find it since you have not even put the file where the code thinks it is!

    And if you had read/understood what I posted earlier you would also realise that the C drive that can been seen by a GEL process running under Clarity is the C drive of the BG server that is running the process and not your local C drive.

    As for "Which is exactly the background server" - I don't know how to answer that, this is YOUR Clarity system not mine, it is YOUR BG server, only YOU have the answer to that. smiley



  • 26.  RE: Gel Scripts in Processes

    Posted 05-22-2014 08:35 AM

    the path I gave is on my local C drive. I don't know how to access the server C drive. Can you help?



  • 27.  RE: Gel Scripts in Processes

    Posted 05-22-2014 08:40 AM

    I don't know how to answer that, this is YOUR Clarity system not mine, it is YOUR BG server, only YOU have the answer to that. smiley

    --

    However, you could simply take the contents of that XML file from your C drive and paste it into the GEL script itself ('inside' the <gel:parse> tags) - this would accomplish the same sort of thing that that script was trying to do by reading the file from the filesystem.
     



  • 28.  RE: Gel Scripts in Processes

    Posted 05-21-2014 05:09 AM

    Please help guys!!