Clarity

 View Only
Expand all | Collapse all

Execute/Parse lookup query from gel

  • 1.  Execute/Parse lookup query from gel

    Posted Mar 08, 2019 12:50 AM

    I have a requirement, where i want to execute some dynamic loookups from gel script. Is there any way to do the same?

     

    we can execute a nsql query using soap call, so is there any way to call lookup in the same way?

     

    or Clarity uses parsers to parse nsql and execute it, so if i can get idea of those parsers so that NSQL for lookup can be parsed in gel and then it can be executed directly there?



  • 2.  Re: Execute/Parse lookup query from gel

    Posted Mar 08, 2019 01:29 AM

    You could write a new query for the required look-ups, for example, below SQL is for Task Status:

    SELECT name FROM cmn_lookups_v
    WHERE lookup_type = 'prTaskStatus'
    AND language_code = 'en'

    which you could then access via SOAP.

     

    I am struggling though, what you are attempting to undertake, as the above SQL (and other SQL), can also be used in GEL scripts directly, without having to call it via SOAP.



  • 3.  Re: Execute/Parse lookup query from gel

    Posted Mar 08, 2019 01:34 AM

    i have so many dynamic lookups. so can not write new sql for all. and sql written for lookups is in NSQL format. 
    how we van access LOokup NSQL via SOAP?



  • 4.  Re: Execute/Parse lookup query from gel

    Posted Mar 11, 2019 11:37 PM

    Create a lookup query that includes all the values you are interested it.

     

    SELECT
    @select:dim:user_def:implied:Dimension:ID:ID@,
    @select:dim_prop:user_def:implied:Dimension:LOOKUP_TYPE:LOOKUP_TYPE@,
    @select:dim_prop:user_def:implied:Dimension:LOOKUP_CODE:LOOKUP_CODE@,
    @select:dim_prop:user_def:implied:Dimension:NAME:NAME@,
    @select:dim_prop:user_def:implied:Dimension:DESCRIPTION:DESCRIPTION@
    FROM(
      SELECT ID, LOOKUP_TYPE, LOOKUP_CODE, NAME, DESCRIPTION
      FROM cmn_lookups_v
      where language_code = 'en'
    )
    Where @FILTER@

     

    In a script use the filter tags to get the values you want.

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script
         xmlns:core="jelly:core"
         xmlns:xog="http://www.niku.com/xog"
         xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
         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:nikuq="http://www.niku.com/xog/Query"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <gel:log>Starting Lookup Test</gel:log>

         <core:set var="Username" value="admin"/>
         <core:set var="Password" value="password"/>
         <core:set var="urlEndpoint" value="https://cppm.ondemand.ca.com/niku/xog"/>
         <core:set var="lookup_type" value="BLB_SLICE_ITEM"/>
         <core:set var="name_wildcard" value="Service*Capital Cost"/>

         <soap:invoke endpoint="${urlEndpoint}" var="runResult">
              <soap:message>
                   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://www.niku.com/xog/Query">
                        <soapenv:Header>
                             <quer:Auth>
                                  <quer:Username>${Username}</quer:Username>
                                  <quer:Password>${Password}</quer:Password>
                             </quer:Auth>
                        </soapenv:Header>
                        <soapenv:Body>
                             <quer:Query>
                                  <quer:Code>LookupQuery</quer:Code>
                                  <quer:Filter>
                                       <quer:lookup_type>${lookup_type}</quer:lookup_type>
                                       <quer:name_wildcard>${name_wildcard}</quer:name_wildcard>
                                  </quer:Filter>
                                  <quer:FilterExpression/>
                             </quer:Query>
                        </soapenv:Body>
                   </soapenv:Envelope>
              </soap:message>
         </soap:invoke>
         
         <gel:log>Invoked LookupQuery</gel:log>
         
         <!-- Get a xml string to print -->
         <core:new className="org.dom4j.io.DOMReader" var="domReader"/>
         <core:invoke on="${domReader}" method="read" var="dom4jDoc">
              <core:arg type="org.w3c.dom.Document"  value="${runResult}" />
         </core:invoke>

         <core:set var="xmlString" value="${dom4jDoc.asXML()}" />
         <gel:log>${xmlString}</gel:log>

         <gel:log>Finish Lookup Test</gel:log>
    </gel:script>

     

    Resulting in.

     

     

     

    V/r,

    Gene



  • 5.  Re: Execute/Parse lookup query from gel

    Posted Mar 12, 2019 04:44 AM

    What should be the value for ‘LookupQuery’.

    I want to execute the some  dynamic lookup sql in my gel script.



  • 6.  Re: Execute/Parse lookup query from gel

    Posted Mar 12, 2019 08:54 AM

     ‘LookupQuery’ is a NSQL Query code, you can't invoke dynamic lookup as PPM dont create web service for lookup's, however,  if you still want to use , Dynamic Lookup SQL in gel then i will suggest fetching sql script from data base table for that lookup and then use that sql script text in sql query tag, also if Dynamic Lookup contains NSQL Syntax then you can use gel's nsqlQuery Tag. its kind of work around, might work in your case. 



  • 7.  Re: Execute/Parse lookup query from gel

    Posted Mar 12, 2019 09:08 AM

    Isn't that what I suggested last week?  Still unclear what Prachi.jain.hcl is attempting to achieve, but he rejected my suggestion last week.

     

    Though I do like Eugene's detailed response, providing exactly what is required, and even including how to pass parameters to make it fully generic.  I would just have included LOOKUP_ENUM to cater for numeric lookups.



  • 8.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 12:35 AM

    Yes, PPM don’t create web service for lookup. That’s why need a way. But if we fetch lookup query that can not be executed directly in sql query tag as it is in NSQL format. We need to parse it. So if someone has an idea of parsers that clarity uses to parse nsql internally, that would be really helpful.



  • 9.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 12:54 AM

    Prachi.jain.hcl,  Eugene has provided a very detailed example of how to achieve this via SOAP.

     

    I have also indicated that the provided sample SQL could also be used in a GEL script.

     

    In addition, you have posted the same question twice, the second posting being Executing Lookup via gel.  In the second posting Urmas has also provided a solution on how this could be achieved by using SQL in the GEL script.  

     

    Urmas also questioned what you are attempting to achieve, which I have also asked twice.

     

    Please review both of your posts, as examples have been provided, and you need to consider if you asking the correct question for the Community to assist further. 



  • 10.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 12:56 AM

    Sure. I will try it. And suggestions provided in communities are always helpful. Really appreciate your help.



  • 11.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 01:02 AM

    My requirement is to get the display value for some of the attributes for multiple objects. So if it is not a lookup, I can directly fetch it from object table. And if it is a static lookup then also it can be fetched easily. But I was facing problem to achieve it for dynamic LOOKUPS. Because for that I need to execute dynamic lookup sql in gel(I cannot hard code dynamic lookup sql in gel as it needs to be done for no of lookups)



  • 12.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 01:17 AM

    You can't 'directly fetch it from object table'  Have a look at the OOTB Query Issue Management which has three joins to different lookups to decode three attributes:

    FROM ODF_ISSUE_V2 I
    INNER JOIN INV_INVESTMENTS inv ON i.pk_id = inv.id
    AND inv.is_active <> 0
    INNER JOIN INV_PROJECTS prj ON i.pk_id = prj.prid
    LEFT OUTER JOIN SRM_RESOURCES r ON i.assigned_to = r.user_id
    LEFT OUTER JOIN PRJ_OBS_ASSOCIATIONS assoc ON inv.id = assoc.record_id
    AND @UPPER@(assoc.table_name) = 'SRM_PROJECTS'
    LEFT OUTER JOIN PRJ_OBS_UNITS_FLAT flat ON assoc.unit_id = flat.unit_id
    LEFT OUTER JOIN CMN_LOOKUPS_V status ON status.lookup_code = i.status_code
    AND status.lookup_type = 'RIM_STATUS'
    AND status.language_code = @WHERE:PARAM:LANGUAGE@
    LEFT OUTER JOIN CMN_LOOKUPS_V category ON category.lookup_code = i.category_type
    AND category.lookup_type = 'RIM_CATEGORY_TYPE'
    AND category.language_code = @WHERE:PARAM:LANGUAGE@
    LEFT OUTER JOIN CMN_LOOKUPS_V priority ON priority.lookup_code = i.priority_code
    AND priority.lookup_type = 'RIM_PRIORITY'
    AND priority.language_code = @WHERE:PARAM:LANGUAGE@

    The bolded section basically the same code, where it uses different lookup_type to determine what Look-up to use. The first lookup is for RIM Status, the second for RIM Category and the third for RIM Priority. The above code could basically be cut-pasted into GEL scripts.  

     

    From V15.4 and above, your SQL needs to include the joins to CMN_LOOKUPS_V.

     

    If you are still using V13.3 to V15.3, there are additional views (eg ODF_ISSUE_V) which did the look-up joins for you, but these were dropped in V15.4.  So basically ignore this paragraph, as if you are using these versions, then they won't exist in future versions, but, you can review the database code behind these views to give you additional insight on how the look-up joins work.



  • 13.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 01:21 AM

    Yes. For static lookup we can fetch it from cmn_lookups_v view by providing lookup type.



  • 14.  Re: Execute/Parse lookup query from gel

    Posted Mar 13, 2019 01:23 AM

    We are in 15.2. I will check the view code.



  • 15.  Re: Execute/Parse lookup query from gel
    Best Answer

    Posted Mar 14, 2019 03:04 AM

    Prachi.jain.hcl ; I have tested a below gel which can be used for nsql scripts.

    <gel:script xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:sql="jelly:sql"
         xmlns:util="jelly:util"
          xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

         
    <gel:setDataSource dbId="niku" var="dataSource"/>

    <gel:nsqlQuery var="resultSet">
      <![CDATA[
      SELECT   @SELECT:U.USER_NAME:USER_NAME@,
               @SELECT:U.ID:USER_ID@
      FROM     CMN_SEC_USERS U
      WHERE    @FILTER@ ]]>

      <gel:nsqlParameter name="user_name_wildcard" value="admin*"/>
    </gel:nsqlQuery>
    <core:forEach items="${resultSet}" var="row">
      <gel:log>USER NAME: '${row.USER_NAME}'</gel:log>
    </core:forEach>  
      
    </gel:script>


  • 16.  Re: Execute/Parse lookup query from gel

    Posted Mar 14, 2019 03:09 AM

    Thanks Prashank. This is helpful. This is what I was looking for.



  • 17.  Re: Execute/Parse lookup query from gel

    Posted Apr 29, 2019 04:17 AM

    To get the value from key-value pair

    <gel:script xmlns:core="jelly:core"
         xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
         xmlns:sql="jelly:sql"
         xmlns:util="jelly:util"
          xmlns:x="jelly:org.apache.commons.jelly.tags.xml.XMLTagLibrary"
         xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

         
    <gel:setDataSource dbId="niku" var="dataSource"/>

    <gel:nsqlQuery var="resultSet">
      <![CDATA[
      SELECT   @SELECT:U.USER_NAME:USER_NAME@,
               @SELECT:U.ID:USER_ID@
      FROM     CMN_SEC_USERS U
      WHERE    @FILTER@ ]]>

      <gel:nsqlParameter name="user_name_wildcard" value="admin*"/>
    </gel:nsqlQuery>
    <core:forEach items="${resultSet}" var="row">
     <core:set value="${row.getValue('user_name')}" var="v_user_name" />
    <core:set value="${row.getValue('first_name')}" var="v_first_name" />
    <gel:log>FirstName: ${v_first_name}</gel:log>
    <gel:log>UserName: ${v_user_name}</gel:log>

    </core:forEach>  
      
    </gel:script>