Clarity PPM

Expand all | Collapse all

Launch a job with parameters from a process

  • 1.  Launch a job with parameters from a process

    Posted 10-03-2017 06:30 AM

    Hello,

    I need to launch a job from a process. The problem is, the job needs the project ID as a parameter. The process will act on a "ThisProject" project instance.
    The job I want to execute is "Purge Financial Tables".

    Thank you very much



  • 2.  Re: Launch a job with parameters from a process

    Posted 10-03-2017 08:42 AM

    Dear Birlain:

       I believe that you meant this for the PPM (Projects) rather than APM (application monitoring) . So I moved it there. Placing your inquiries in the right community will ensure a timely response. 

     

    Thanks

    Hal German



  • 3.  Re: Launch a job with parameters from a process

    Posted 10-03-2017 09:05 AM

    Similar to this

     

    Launch a job from gel.

    https://communities.ca.com/message/97674357  

     

    Regards

    NJ



  • 4.  Re: Launch a job with parameters from a process

    Posted 10-03-2017 09:08 AM

    Also, this

     

    Run Parameterised Job via GEL & Process

    https://communities.ca.com/message/241716925  

     

     

    NJ



  • 5.  Re: Launch a job with parameters from a process

    Posted 10-03-2017 09:09 AM

    launching a job or report from GEL script 

    https://communities.ca.com/message/241745549

     

     

    NJ



  • 6.  Re: Launch a job with parameters from a process

    Posted 10-03-2017 09:41 AM

    Thanks for the answers,

    This is what I would like to do with the process (Run Parameterised Job via GEL & Process). But there is no right answer.



  • 7.  Re: Launch a job with parameters from a process

    Posted 10-18-2017 04:53 PM

    Hi Birlain - We're you ever able to figure this one out? Thanks, Chris



  • 8.  Re: Launch a job with parameters from a process

    Posted 10-19-2017 02:11 AM

    Hi Chris, no, the problem remains unsolved.

    a greeting



  • 9.  Re: Launch a job with parameters from a process

    Posted 10-23-2017 12:05 PM

    Thinking about this, one would need to (inside a gel script step):

     

    1. Get a hold of the scheduler via the SchedulerFactory class.
    2. Create a new job to run (would need to figure out the class).
    3. Set the job schedule start date to now along with the recurrence now flag.
    4. Create an ArrayList to hold the needed job parameters.
    5. Populate the ArrayList with the jobs required parameters.
    6. Set the schedulelistener on the job to the scheduler obtained in step 1.

     

    The hard part of this is to determine the job parameters that are needed and get the correct tokens and type mappings.

     

    The other option I was kicking around in my head, was to just run the "Purge Financial Tables" job without the scheduler. Each schedule job implements the SchedulerListener class in which the scheduledEventFired is implmement to perform the needed logic. 

     

    The scheduledEventFired method has a single parameter of type JobSchedulerContext.  So one might be able to create a JobSchedulerContext that would satisfy the scheduledEventFired in order to execute it outside the scheduler.

     

    I have never tried either of this approaches so I am not sure how successful one would be.

     

     

    V/r,

    Gene



  • 10.  Re: Launch a job with parameters from a process

    Posted 10-24-2017 06:46 PM

    So I was able to fire a scheduled job via a process.  In my test case, I define a process that fires a ExecuteProcessJob for another process.

     

    You need a couple to things to configure the gel action script.

     

    You need the id for the via the address – in my test I am using com.niku.bpm.jobs.ExecuteProcessJob.

    You will also need the securityIdentifier that the process is running under along with the current date to schedule the execution.

     

     

    So my process which I fire is called Debug Schedule that I fire via the Organizer.

     

     

    I see that my process runs and we also see the SystemConfigurationFiles process is run via the scheduler

     

     

    So here is the gel action script.

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:core="jelly:core"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <core:catch var="v_exception">
         
              <!-- setup some variables we will need -->
              <core:new className="java.util.Date" var="now" />
              <core:set value="${context.getSecurityIdentifier()}" var="securityIdentifier" />
              <core:new var="jobId" className="java.lang.Long">
                   <core:arg type="java.lang.String" value="50560" />
              </core:new>

              <!-- get the scheduler -->
              <core:invokeStatic className="com.niku.union.njs.SchedulerFactory" method="getInstance" var="scheduler" />
              <gel:log>invokeStatic scheduler: ${scheduler.toString()}</gel:log>
              
              <!-- need a job to submit to the scheduler base on our job definition-->
              <core:invokeStatic className="com.niku.njs.JobImpl" method="retrieveJob" var="jobImpl">
              <core:arg type="long" value="${jobId}"/>
              <core:arg type="com.niku.union.security.SecurityIdentifier" value="${securityIdentifier}"/>
              </core:invokeStatic>
              <gel:log>new jobImpl: ${jobImpl.getParamsAsString()}</gel:log>
              
              <!-- define our parameters we need for this job and add them to the job -->
              <core:new className="java.util.ArrayList" var="jobParameters" />          
              <core:new className="com.niku.njs.JobParameter" var="param1">
                   <core:arg type="java.lang.String" value="param_run_single_instance"/>
                   <core:arg type="java.lang.String" value="1"/>
                   <core:arg type="java.lang.String" value="java.lang.String"/>
              </core:new>
              <core:new className="com.niku.njs.JobParameter" var="param2">
                   <core:arg type="java.lang.String" value="param_process_code"/>
                   <!-- shedule the SystemConfigurationFiles process to run via the scheduler -->
                   <core:arg type="java.lang.String" value="SystemConfigurationFiles"/>
                   <core:arg type="java.lang.String" value="java.lang.String"/>
              </core:new>
              <core:invoke method="add" on="${jobParameters}" var="dummy">
                   <core:arg value="param1"/>
              </core:invoke>
              <core:invoke method="add" on="${jobParameters}" var="dummy">
                   <core:arg value="param2"/>
              </core:invoke>
              <core:set value='${jobImpl.setParams(jobParameters)}' var='dummy' />
              <gel:log>add jobParameters: ${jobParameters.toString()}</gel:log>

              <!-- Set some job properties mostly run now -->
              <core:set value='${jobImpl.setScheduleDate(now)}' var='dummy' />
              <core:set value='${jobImpl.setStartDate(now)}' var='dummy' />
              <core:set value='${jobImpl.setRecurNow(true)}' var='dummy' />
              <core:invoke method="setSchedulerListener" on="${jobImpl}" var="dummy">
                   <core:arg type="java.lang.String" value="JAVA"/>
                   <core:arg type="java.lang.String" value="com.niku.bpm.jobs.ExecuteProcessJob"/>
              </core:invoke>
              <gel:log>set jobImpl: ${jobImpl.toString()}</gel:log>
              
              <!-- schedule the job with the scheduler -->
              <core:invoke method="schedule" on="${scheduler}" var="dummy">
                   <core:arg type="com.niku.njs.JobImpl" value="${jobImpl}"/>
              </core:invoke>
              <gel:log>invoke schedule: ${schedule.toString()}</gel:log>

         </core:catch>
         <core:choose>
              <!-- Check for errors -->
              <core:when test="${v_exception != null}">
                   <gel:log>Error: ${v_exception}</gel:log>
              </core:when>
              <core:otherwise/>
         </core:choose>
    </gel:script>

     

    V/r,

    Gene



  • 11.  Re: Launch a job with parameters from a process

    Posted 05-08-2018 09:19 AM

    Hi gcubed,

     

    I'm using your script to run the Purge Financial Tables job via a process and it gives me an error line no. 60. I used your process as is for running a non-object based process and it fails at line 60 again. Also, the jobImpl.getParamsAsString() method returns as null. 

     

    It doesn't seem to find the job with the ID. But, the job ID for Purge Financial Tables job is 5000042. I'm not sure what could be wrong.

     

     

    Is there anything more I need to configure for this to work?

     

    Thanks in advance,

     

    Leo.



  • 12.  Re: Launch a job with parameters from a process

    Posted 05-10-2018 10:24 AM

    you should be using the Job ID from the Scheduled Jobs view but not the Job Definition ID as shown in the example script. Also, I had to enclose the parameter values with ${} as above changing from

     <core:arg value="param2"/>

    to 

     <core:arg value="${param2}"/>

     

     

    The problem that I am facing is that context.getSecurityIdentifier() returns -1. What is the PPM version you are using?



  • 13.  Re: Launch a job with parameters from a process

    Posted 05-11-2018 02:37 AM

    Hi vaicemar


    Thank you for mentioning I had to use the Job ID from scheduled jobs and not the Definition ID. I had enclosed the parameters correctly. I'm able to run the job now. However, if we are scheduling the job we need to specify the parameter in the job. I want the parameters to set dynamically via the script. 

     

    Here's what I tried, I scheduled the "Execute a process" job to run a process "ABC" and then from the script I set the parameters to run the process "check_email" and executed it. But, it ran the process "ABC". 

     

    Any ideas on how to do that?

     

    For getting the securityIdentifier you can use the below code. 

     

    <?xml version="1.0" encoding="utf-8"?>
    <gel:script xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:core="jelly:core"
        xmlns:gel="jelly:com.niku.union.gel.GELTagLibrary"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


         <core:catch var="v_exception">
               
              <!-- setup some variables we will need -->
              <core:new className="java.util.Date" var="now" />
              <!--<core:set value="${context.getSecurityIdentifier()}" var="securityIdentifier" />-->
                <core:invokeStatic className="com.niku.union.security.UserSessionControllerFactory" method="getInstance" var="sessionController"/>
                <core:invoke method="init" on="${sessionController}" var="securityIdentifier">
                        <core:arg value="admin"/>
                   </core:invoke>
              <core:new var="jobId" className="java.lang.Long">
                   <core:arg type="java.lang.String" value="5023001" />
              </core:new>
               
              <!-- get the scheduler -->
              <core:invokeStatic className="com.niku.union.njs.SchedulerFactory" method="getInstance" var="scheduler" />
              <gel:log>invokeStatic scheduler: ${scheduler.toString()}</gel:log>
               
                <core:invokeStatic className="com.niku.njs.JobImpl" method="retrieveJob" var="jobImpl">
              <core:arg type="long" value="${jobId}"/>
              <core:arg type="com.niku.union.security.SecurityIdentifier" value="${securityIdentifier}"/>
              </core:invokeStatic>
               
                <!-- define our parameters we need for this job and add them to the job -->
              <core:new className="java.util.ArrayList" var="jobParameters" />         
              <core:new className="com.niku.njs.JobParameter" var="param1">
                   <core:arg type="java.lang.String" value="param_run_single_instance"/>
                   <core:arg type="java.lang.String" value="1"/>
                   <core:arg type="java.lang.String" value="java.lang.String"/>
              </core:new>
              <core:new className="com.niku.njs.JobParameter" var="param2">
                   <core:arg type="java.lang.String" value="param_process_code"/>
                   <!-- shedule the check_email process to run via the scheduler -->
                   <core:arg type="java.lang.String" value="check_email"/>
                   <core:arg type="java.lang.String" value="java.lang.String"/>
              </core:new>
              <core:invoke method="add" on="${jobParameters}" var="dummy">
                   <core:arg value="${param1}"/>
              </core:invoke>
              <core:invoke method="add" on="${jobParameters}" var="dummy">
                   <core:arg value="${param2}"/>
              </core:invoke>
               
              <!--<core:set value='${jobImpl.setParams(jobParameters)}' var='dummy' />-->
                <core:invoke method="setParams" on="${jobImpl}" var="dummy">
                   <core:arg type="java.util.ArrayList" value="${jobParameters}"/>
              </core:invoke>
              <gel:log>add jobParameters: ${jobImpl.getParamsAsString()}</gel:log>

             
             
              <!-- need a job to submit to the scheduler base on our job definition-->
              <!--<core:new className="com.niku.njs.JobImpl" var="jobImpl"/>-->
              <!-- Set some job properties mostly run now -->
               
              <core:set value='${jobImpl.setName("Leo job via process")}' var='dummy' />
               
                <core:invoke method="setStartDate" on="${jobImpl}">
                   <core:arg type="java.util.Date" value="${now}"/>
              </core:invoke>
                <core:invoke method="setEndDate" on="${jobImpl}">
                   <core:arg type="java.util.Date" value="${now}"/>
              </core:invoke>
                <core:invoke method="setMinutes" on="${jobImpl}">
                   <core:arg value="0-59/2"/>
              </core:invoke>
                <!--
                <core:invoke method="setId" on="${jobImpl}">
                   <core:arg type="long" value="5023001"/>
              </core:invoke>
                -->

                <core:set value='${jobImpl.setRecurNow(true)}' var='dummy' />
               
              <core:invoke method="setSchedulerListener" on="${jobImpl}" var="dummy">
                   <core:arg type="java.lang.String" value="JAVA"/>
                   <core:arg type="java.lang.String" value="com.niku.bpm.jobs.ExecuteProcessJob"/>
              </core:invoke>
              <gel:log>set jobImpl: ${jobImpl.toString()}</gel:log>
               
             
              <core:invoke method="setStatus" on="${jobImpl}">
                   <core:arg value="NOT_SCHEDULED"/>
              </core:invoke>
             
              <!-- schedule the job with the scheduler -->
              <core:invoke method="schedule" on="${scheduler}">
                   <core:arg type="com.niku.njs.JobImpl" value="${jobImpl}"/>
              </core:invoke>

                   
         </core:catch>
         <core:choose>
              <!-- Check for errors -->
              <core:when test="${v_exception != null}">
                   <gel:log level="ERROR">Error: ${v_exception}</gel:log>
              </core:when>
              <core:otherwise/>
         </core:choose>
    </gel:script>


  • 14.  Re: Launch a job with parameters from a process

    Posted 05-11-2018 05:14 AM

    Execute the process from the GUI as you would like it to run automatically. Then check the Job logs for the last execution and fetch the job id from there. Use that id in your script and it should work fine. Also, remember to check bg-ca.log it usually provides some useful information.

     

    Here is my working example for invoking "Update Actuals from Estimates" job using gel action

     

     

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

    <gel:log>version 1.0 </gel:log>
    <core:catch var="v_exception">
    <core:new className="java.util.Date" var="now" />
    <core:new var="jobId" className="java.lang.Long">
    <core:arg type="java.lang.String" value="5062148" />
    </core:new>
    <!-- get security ID -->
    <core:invokeStatic className="com.niku.union.utility.UtilityThreadLocal" method="getSecurityIdentifier" var="utlSecID" />
    <gel:log>utl user id: ${utlSecID.getUserId()}</gel:log>
    <gel:log>utlSecID: ${utlSecID.toString()}</gel:log>

    <!-- get the scheduler -->
    <core:invokeStatic className="com.niku.union.njs.SchedulerFactory" method="getInstance" var="scheduler" />
    <gel:log>invokeStatic scheduler: ${scheduler.toString()}</gel:log>

    <!-- need a job to submit to the scheduler base on existing job id-->
    <core:invokeStatic className="com.niku.njs.JobImpl" method="retrieveJob" var="jobImpl">
    <core:arg type="long" value="${jobId}"/>
    <core:arg type="com.niku.union.security.SecurityIdentifier" value="${utlSecID}"/>
    </core:invokeStatic>
    <gel:log>new jobImpl: ${jobImpl.getParamsAsString()}</gel:log>

    <!-- define our parameters we need for this job and add them to the job -->
    <core:new className="java.util.ArrayList" var="jobParameters" />
    <core:new className="com.niku.njs.JobParameter" var="param1">
    <core:arg type="java.lang.String" value="project_name"/>
    <core:arg type="java.lang.String" value="Test"/>
    <core:arg type="java.lang.String" value="java.lang.String"/>
    </core:new>

    <core:invoke method="add" on="${jobParameters}" var="dummy">
    <core:arg value="${param1}"/>
    </core:invoke>

    <core:set value='${jobImpl.setParams(jobParameters)}' var='dummy' />
    <gel:log>add jobParameters: ${jobParameters.toString()}</gel:log>

    <!-- Set some job properties mostly run now -->
    <core:set value='${jobImpl.setScheduleDate(now)}' var='dummy' />
    <core:set value='${jobImpl.setStartDate(now)}' var='dummy' />
    <core:set value='${jobImpl.setEndDate(now)}' var='dummy' />
    <core:set value='${jobImpl.setRecurNow(true)}' var='dummy' />
    <core:set value='${jobImpl.setStatus("NOT_SCHEDULED")}' var='dummy' />
    <core:set value='${jobImpl.setSchedulerListener("JAVA", "com.niku.projmgr.jobs.UpdateTeamAllocationData")}' var='dummy' />
    <gel:log>run jobImpl: ${jobImpl.toString()}</gel:log>
    <!-- schedule the job with the scheduler -->
    <core:invoke method="schedule" on="${scheduler}" var="dummy">
    <core:arg type="com.niku.njs.JobImpl" value="${jobImpl}"/>
    </core:invoke>
    <gel:log>invoke schedule: ${scheduler.toString()}</gel:log>
    <gel:log>Status: ${jobImpl.getStatus()}</gel:log>
    </core:catch>
    <core:choose>
    <!-- Check for errors -->
    <core:when test="${v_exception != null}">
    <gel:log>Error: ${v_exception}</gel:log>
    </core:when>
    <core:otherwise/>
    </core:choose>


    </gel:script>