This attached GEL script will run a Clarity Java job with the Job definition ID and needed parameters. You do not need the schedule job id from the job log to run the job.
This job definition ID ca be picked up from the table CMN_SCH_JOB_DEFINITIONS,
say for "Post to WIP Job"
select ID from CMN_SCH_JOB_DEFINITIONS
where JOB_CODE = 'POST_TO_WIP'
--5000576
or, can be fetched from the URL of the Job definition in Clarity admin side,
say for example for Post to WIP Job the URL is ../niku/nu#action:njs.editProgram&id=5000576
You can use this attached script to Execute Post to WIP job. Add the additional parameters to the parameter definitions section of this script based on the parameters specified under the job definition in Clarity.
<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">
<!--
Process to run a Clarity Java job with parameters
version 1.0
-->
<core:catch var="v_exception">
<core:new className="java.util.Date" var="now" />
<!-- Job Definition ID of the Calrity job -->
<core:new var="jobId" className="java.lang.Long">
<core:arg type="java.lang.String" value="5000576" />
</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>
<!-- define parameters needed to run this job and add them to the variable jobParameters -->
<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_inv"/>
<core:arg type="java.lang.String" value="5194887"/>
<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:new className="com.niku.njs.JobParameter" var="param2">
<core:arg type="java.lang.String" value="param_post_options"/>
<core:arg type="java.lang.String" value="POST_TO_WIP"/>
<core:arg type="java.lang.String" value="java.lang.String"/>
</core:new>
<core:invoke method="add" on="${jobParameters}" var="dummy">
<core:arg value="${param2}"/>
</core:invoke>
<!-- Schedule/Run the job with job id-->
<core:new className="com.niku.njs.JobScheduler" var="scheduleJobId" />
<core:set value="${scheduleJobId.scheduleJobWithParams(jobId, 'Post to WIP - OnDemand', jobParameters, utlSecID)}" var="scheduleJobId"/>
<gel:log>Schedule Job ID: ${scheduleJobId}</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>
Original Message:
Sent: Apr 22, 2022 07:12 AM
From: RAJARAM MADDULA
Subject: Re: Launch a job with parameters from a process
Hi Jeevana Battu,
Please let me know if you were able to find any solution for this.
Best Regards,
Mohan
Original Message:
Sent: Jan 16, 2022 10:19 PM
From: Jeevana Battu
Subject: Re: Launch a job with parameters from a process
Hi Marius,
I am aware that this is older thread. I tried the code you posted, but it is not picking the parameter and running for all the projects.
Could you please help me ?
Thanks,
Jeevana.
Original Message:
Sent: May 11, 2018 05:14 AM
From: Marius Vaicekauskas
Subject: Re: Launch a job with parameters from a process
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>
<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>
<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="${utlSecID}"/>
</core:invokeStatic>
<gel:log>new jobImpl: ${jobImpl.getParamsAsString()}</gel:log>
<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>
<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>
<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>
<core:when test="${v_exception != null}">
<gel:log>Error: ${v_exception}</gel:log>
</core:when>
<core:otherwise/>
</core:choose>
</gel:script>