Clarity

Expand all | Collapse all

GEL script to XOG object using SOAP

  • 1.  GEL script to XOG object using SOAP

    Posted Oct 12, 2010 07:08 AM
    Hi,

    We have the following requirement to implement in Clarity:

    When a Project phase is changed, the sub-object instances "Project SDLC Questions" must be evaluated with the new phase.

    Basically when we create a new project a series of "SDLC Questions" are also created for this project. This sub-object has Project as parent object.

    When the project phase is changed from Envisioning to Planing, for example, each one of the SDLC Question instances related to the current project must be reevaluated.

    Currently, we have a process that is fired up when the SDLC Question object is updated in order to evaluate the object and according to a series of filters determine its current status. Since we need to reevaluate all SDLC Questions from a project when its phase is changed we thought about using a GEL script to loop through each of the SDLC Question object instances and update them using XOG in order to fire the process that is supposed to fire when the object is updated.

    I was trying to do that using a GEL script that does a SOAP invoke in order to update that object. Here it is the GEL code:
    <gel:script xmlns:x="jelly:xml"
    xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
    xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
    xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:core="jelly:core"
    xmlns:sql="jelly:sql"
    xmlns:xog="http://www.niku.com/xog">
    
    <gel:parameter var="XOGusername" default="***"/>
    <gel:parameter var="XOGpassword" default="yyy"/>
    
    <soap:invoke endpoint="http://ausgchrwluat2:10202/niku/xog" var="result">
    <soap:message>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xog="http://www.niku.com/xog">
          <soapenv:Body>
            <xog:Login xmlns:xog="http://www.niku.com/xog">
              <xog:Username>${XOGusername}</xog:Username>
    
    
      <xog:Password>${XOGpassword}</xog:Password>
    
    
      </xog:Login>                        
    
    
    
    <!-- start of XOG script -->
           <obj:WriteCustomObjectInstance xmlns:obj="http://www.niku.com/xog/Object">
    
    
    
    
    
    
    
    <NikuDataBus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    
    
    
    
    
    
    
    xsi:noNamespaceSchemaLocation="../xsd/nikuxog_customObjectInstance.xsd">
    
    
    
    
    
    
    
    
    <Header externalSource="NIKU" version="7.5"/>
    
    
    
    
    
    
    
    <customObjectInstances objectCode="id">
    
    
    
    
    
    
    
    
    <instance instanceCode="5011660" objectCode="dell_sdlc_prj_quest">
    
    
    
    
    
    
    
    
    
    <CustomInformation>
    
    
    
    
    
    
    
    
    
    
    <ColumnValue name="name">TEST665</ColumnValue>
    
    
    
    
    
    
    
    
    
    
    <ColumnValue name="dell_sdlc_desc">TEST888</ColumnValue>
    
    
    
    
    
    
    
    
    
    </CustomInformation>
    
    
    
    
    
    
    
    
    
    <OBSAssocs/>
    
    
    
    
    
    
    
    
    </instance>
    
    
    
    
    
    
    
    </customObjectInstances>
    
    
    
    
    
    
    </NikuDataBus>
    
    
    
    
    
    
    
    </obj:WriteCustomObjectInstance>
    
    
    
    <!-- end of XOG script -->
    
    
    </soapenv:Body>
    
    
    </soapenv:Envelope>
    
    
    </soap:message>
    </soap:invoke>
    
    <gel:out>${result}</gel:out>
    
    </gel:script>
    I am running that script from my machine and this is the only answer I get:
    [#document: null]

    Checking the database and the interface I can see that the process is not running after I've executed the GEL script.

    It seems the GEL script is not able to connect to the XOG and execute the WRITE operation.

    I would appreciate any insights on a possible solution to my requirement as well as to why the above code does not works as it is supposed to.

    Thanks,

    Fabricio


  • 2.  RE: GEL script to XOG object using SOAP
    Best Answer

    Posted Oct 12, 2010 07:08 AM
    Hi,

    I have written a few GEL scripts that call XOG, but I have never tried to do it "all in one go" like in your example. (I'm not saying that you can't do this though!)

    When I do this I do it in a couple of stages;

    SOAP message to logon to Clarity (returns SessionID)

    SOAP message to call XOG (passing Session ID in the message).

    --

    If you look at the "Running the XOG" example in the "GEL for Dummies" document in the Gel.zip file attached to the FAQ thread; CLICK HERE, that has the example GEL in it (which is what I use!).

    Hope that helps?


  • 3.  RE: GEL script to XOG object using SOAP

    Posted Oct 12, 2010 07:08 AM
    Hi,

    Thanks for your reply, I did find some useful information in there.

    I am able to log and get the SESSION ID now.

    Now I will work in the other piece which is update a custom object using XOG.

    Thanks,

    Fabricio


  • 4.  RE: GEL script to XOG object using SOAP

    Posted Jul 30, 2012 04:49 AM
    Hi Dave

    Is there a way to print this SessionID ?

    I am using the following code, but it returns BLANK value -

    <gel:set asString="true" select="$auth/SOAP-ENV:Envelope/SOAPENV:Body/xog:SessionID/text()" var="sessionID"/>
    <gel:log level="INFO" category="XOG">Log in successful ${sessionID}</gel:log>

    Thanks
    -=S


  • 5.  RE: GEL script to XOG object using SOAP

    Posted Jul 30, 2012 04:55 AM
    Are you sure that is the correct XPath? I believe the response is the contents of the body, you don't have to drill down through it (I could be mistaken from memory, but either way using a // in the XPath should overcome the path navigation difficulties for this purpose):
    ...
    <!-- login / get session ID first -->
    <soap:invoke var="auth" endpoint="${endpoint}" > 
      <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>${user}</xog:Username>
              <xog:Password>${pass}</xog:Password>
            </xog:Login> 
          </soapenv:Body> 
        </soapenv:Envelope> 
      </soap:message> 
    </soap:invoke>
    
    <gel:set asString="true" select="$auth//xog:SessionID/text()" var="sessionID" />
    ...
    Also make sure you have your namespaces declared:
    <gel:script
    ...
    xmlns:soapenv="http://schema.xmlsoap.org/soap/envelope/"
    xmlns:xog="http://www.niku.com/xog"
    ...


  • 6.  RE: GEL script to XOG object using SOAP

    Posted Jul 30, 2012 05:05 AM
    I was mistaken - the full response is something like this (<gel:serialize> can write the full xml of any response to disk for you to check):
    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
        <soapenv:Header/>
        <soapenv:Body>
            <SessionID xmlns="http://www.niku.com/xog">5125401__1BC0D6C0-6AA3-458D-B288-FA88EEBEAAE6</SessionID>
        </soapenv:Body>
    </soapenv:Envelope>
    So the XPath to get to it is either $auth//xog:SessionID/text() or $auth/soapenv:Envelope/soapenv:Body/xog:SessionID/text() - either of those should work fine for your needs. I notice in your own example that your namespace for the SOAP envelope has a typo in one or other place (unless you defined it both ways).


  • 7.  RE: GEL script to XOG object using SOAP

    Posted Sep 17, 2012 12:29 PM
    Hello Everyone,

    I am trying to get the response for the Invoke action SOAP call, though the script executes successfully and initiating the process but the response is always null. Please help me in reading the response

    <gel:script xmlns:core="jelly:core" xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary" xmlns:xog="http://www.niku.com/xog"
    xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
    <soap:invoke endpoint="http://myserver/niku/xog" var="result">
    <soap:message>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://www.niku.com/xog/InvokeAction">
    <soap:Header>
    <tns:Auth>
    <tns:Username>username</tns:Username>
    <tns:Password>pwd</tns:Password>
    </tns:Auth>
    </soap:Header>
    <soap:Body>
    <tns:Process>
    <code>Process name</code>
    <request/>
    </tns:Process>
    </soap:Body>
    </soap:Envelope>
    </soap:message>
    </soap:invoke>

    <gel:serialize fileName="clarity-process.log" var="${result}"/>

    <gel:set asString="true" select="$result/soap:Envelope/soap:Body/ProcessResponse/ProcessResult" var="Output"/>

    <gel:out>DEBUG INFO ${Output}</gel:out>
    </gel:script>

    The output file is returning only the session id.

    <?xml version="1.0" encoding="UTF-8"?>
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
    <SessionID xmlns="http://www.niku.com/xog">5613133__DBEEEB1B-39E9-4A63-AF00-4D4B8F5CB5EE</SessionID>
    <ProcessResult xmlns="http://www.niku.com/xog/InvokeAction"/>
    </soapenv:Body>
    </soapenv:Envelope>


  • 8.  RE: GEL script to XOG object using SOAP

    Posted Sep 19, 2012 10:34 AM
    Note the following lines in your GEL script:
    xmlns:soap="jelly:com.niku.union.gel.SOAPTagLibrary"
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    ...
    <gel:set asString="true" select="$result/soap:Envelope/soap:Body/ProcessResponse/ProcessResult" var="Output"/>

    And the namespace URL(s) in the output:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <SessionID xmlns="http://www.niku.com/xog">5613133__DBEEEB1B-39E9-4A63-AF00-4D4B8F5CB5EE</SessionID>
    <ProcessResult xmlns="http://www.niku.com/xog/InvokeAction"/>

    This:
    <gel:set asString="true" select="$result/soap:Envelope/soap:Body/ProcessResponse/ProcessResult" var="Output"/>

    At the very least would need to be changed to this:
    <gel:set asString="true" select="$result/soapenv:Envelope/soapenv:Body/invoke:ProcessResult" var="Output"/>

    And add this in the namespaces in the top of your <gel:script> opening tag:
    xmlns:invoke="http://www.niku.com/xog/InvokeAction"

    Example:
    <gel:script 
      xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
      xmlns:invoke="http://www.niku.com/xog/InvokeAction"
    >
    
    <gel:parse var="xog_data">
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
    <SessionID xmlns="http://www.niku.com/xog">5613133__DBEEEB1B-39E9-4A63-AF00-4D4B8F5CB5EE</SessionID>
    <ProcessResult xmlns="http://www.niku.com/xog/InvokeAction"/>
    </soapenv:Body>
    </soapenv:Envelope>
    </gel:parse>
    
    <gel:set asString="true" select="$xog_data/soapenv:Envelope/soapenv:Body/invoke:ProcessResult" var="xog_output" />
    <gel:out>${xog_output}</gel:out>
    </gel:script>
    C:\>\Clarity\12.1.3\bin\gel -script example.gel
    <ProcessResult xmlns="http://www.niku.com/xog/InvokeAction"/>

    C:\>


  • 9.  RE: GEL script to XOG object using SOAP

    Posted Sep 19, 2012 12:46 PM
    Thanks Nick.
    Now I am able to the Process result as what you mentioned however is there any way to find wheather the process initiated sucessfully or not.

    Thanks in Advance,
    Karthik


  • 10.  RE: GEL script to XOG object using SOAP

    Posted Sep 20, 2012 04:41 AM
    No pre-canned method I can think of, however you could create an NSQL query that examines the bpm_run_processes table for new instances. You'd be more likely to get a certain match (in the event there could be 3 similar process instances fired off in rapid succession) by having those process instances take in a 'request' in the body of the process invoke action, which contains some identifiable/key information (possibly the session ID if each is done with a separate login/logout).

    <Process xmlns="http://www.niku.com/xog/InvokeAction">
    <code>your_process_code</code>
    <request>
    <your_custom_xml>
    <sessionID>12345678901234567890</sessionID>
    </your_custom_xml>
    </request>
    </Process>

    Your process can then in a GEL script call the <gel:getDocument> tag to retrieve the xml fragment beginning with the <your_custom_xml> root node to store a reference to this process being launched, which is retrieved again through your NSQL query. Just beware that there can sometimes be a delay in the actual starting up of the process instance, so if your web services run quickly enough, then a polling method may not be that great.

    Alternatively, if you can also provide web services to consume, then instead of polling, the GEL script could use the information in the request to initiate a call-back to advise when it has started the process instance associated with the request. This would be better on resources but require you to implement your 'retry' method (or other reason for needing to absolutely know the process was initiated) to be asynchronous too.


  • 11.  RE: GEL script to XOG object using SOAP

    Posted Sep 24, 2012 08:58 AM
    Thanks Nick.So I think we don't have teh direct way of getting the response on process Initiated.As suggested we will find some way to find thatusing the NSQL.