Clarity

 View Only
Expand all | Collapse all

How to run parametrized Job through a process?

  • 1.  How to run parametrized Job through a process?

    Posted Jan 11, 2022 10:25 AM
    Hi,

    I have a requirement where we need to run 'Update Cost Totals' job from a process where I should pass dynamic Project values in it.

    I found something in communities but that is not picking dynamic Project Id.

    Please help!!

    Thanks,
    Jeevana.


  • 2.  RE: How to run parametrized Job through a process?

    Posted Jan 12, 2022 04:21 AM
    Can you post the code so we can see what might be going wrong?

    Paul


  • 3.  RE: How to run parametrized Job through a process?

    Posted Jan 12, 2022 04:48 AM
      |   view attached
    Hi Paul,

    I am attaching the code here, I tried with Internal id, Project id and name as well. 'Update cost totals' job is running but not picking any parameter value.

    Thanks,
    Jeevana.

    Attachment(s)

    xml
    Job script.xml   3 KB 1 version


  • 4.  RE: How to run parametrized Job through a process?

    Posted Jan 12, 2022 05:51 AM
    Thanks for this. Let me adjust the identities etc., so I can try it on my system. Just to start things off though, what do the hard coded numbers represent? On my system that job has a job_definition_id of 5000046.

    Paul


  • 5.  RE: How to run parametrized Job through a process?

    Posted Jan 12, 2022 06:17 AM
    Hi Paul,


    1st hardcoded value - 5254330 , is the Scheduled job ID(we need to schedule 'Update cost Totals' job and give this ID in the script, so every time the process picks this Scheduled job and run it)
    2nd  hardcoded value - 5088731, is the Idea Internal id

    Please let me know if you figure out things I am missing ?

    Thanks,
    Jeevana.


  • 6.  RE: How to run parametrized Job through a process?

    Posted Jan 13, 2022 11:48 AM
      |   view attached
    Hello again,

    I'm assuming that the job you mean is the Update Earned Value and Cost Totals job, but that's a detail. In my system that has an internal Job ID of 5000046. Here is what I did.

    1) Created a scheduled job for that job with no end date that runs on Sundays, with a start date in the future:

    This scheduled job has an internal ID of 5042064.

    2) Next I created a job process on the project object using the script you attached as the base, but with some minor changes. The main ones are the Job ID is picked up from a parameter and the Project ID is determined at run time, rather than hard-coding them. I've attached the script to this reply.

    3) I opened the project, navigated to the processes tab and executed the process. The log looks like this:
    Which suggests the process has scheduled the job.

    4) I went into the Scheduled Job and navigated to the instances that have been executed and it looks like the job ran OK:

    Is that what you need, or have I misunderstood?

    Paul

    Attachment(s)

    xml
    Job script.xml   3 KB 1 version


  • 7.  RE: How to run parametrized Job through a process?

    Posted Jan 13, 2022 10:47 PM
    Hi Paul,

    Thanks for trying this out.

    Could you please confirm if the Job is picking that particular project instance or running for all? Even before the job is running for me but not picking particular Project/Idea.




  • 8.  RE: How to run parametrized Job through a process?

    Posted Jan 14, 2022 12:18 AM
    Apologies for not checking that. The job is being run with the parameters all blank, and hence for all projects as you say. I'll take another look. Just one more question though... Is the intention to generalise the script so that it calls the job for several projects, or is the number of projects (or ideas) very small and the ones it needs to run for are known in advance?


  • 9.  RE: How to run parametrized Job through a process?

    Posted Jan 14, 2022 01:46 AM
    I tried this again using the original code from here: https://community.broadcom.com/communities/community-home/digestviewer/viewthread?MID=771138#bm04e7d33d-4d0a-4ea1-9daf-c76127aa8ecd (I guess this is where you found the example as it looks very similar), but that didn't work either. The job executes for all projects. I don't know what the issue is as the original says it worked fine. I'll continue digging....



  • 10.  RE: How to run parametrized Job through a process?

    Posted Jan 16, 2022 10:11 PM
    Hi Paul,

    Yes, you are right. The thread you mentioned is where I got the code.

    Thank you so much for your help, Please help me resolve this issue.

    Thanks,
    Jeevana.


  • 11.  RE: How to run parametrized Job through a process?

    Posted Jan 23, 2022 11:38 PM
    Hi Paul,

    Any luck on this issue?

    Thanks,
    Jeevana.


  • 12.  RE: How to run parametrized Job through a process?

    Posted Jan 24, 2022 02:33 AM
    I've posted my findings twice on this thread but they don't seem to stick.

    I'll try again without the code.

    Basically I set up all four parameters (the last 3 being null) and then echoed the parameters back again after oulling them back again as in the original code.

    They are all blank so I think that setting the parameters doesn't work as expected.


  • 13.  RE: How to run parametrized Job through a process?

    Posted Feb 01, 2022 04:43 PM
    Hello again,

    I did do some more digging but it looks like the reply didn't post. Setting the parameters doesn't seem to work.

    I added a few more lines and echoes the original parameters as follows:

    <!-- 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>Default parameters: ${jobImpl.getParamsAsString()}</gel:log>

    I added all four parameters as follows:

    <!-- 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="projectId"/>
    <core:arg type="java.lang.String" value="${project_id}"/>
    <core:arg type="java.lang.String" value="${parameter_type}"/>
    </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="projectOBSunit"/>
    <core:arg type="java.lang.String" value="null"/>
    <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>

    <core:new className="com.niku.njs.JobParameter" var="param3">
    <core:arg type="java.lang.String" value="projectOBSmode"/>
    <core:arg type="java.lang.String" value="null"/>
    <core:arg type="java.lang.String" value="java.lang.String"/>
    </core:new>

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

    <core:new className="com.niku.njs.JobParameter" var="param4">
    <core:arg type="java.lang.String" value="managerId"/>
    <core:arg type="java.lang.String" value="null"/>
    <core:arg type="java.lang.String" value="java.lang.String"/>
    </core:new>

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

    I then echoed the updated parameters to the log and set them as in the original script:

    <gel:log>Updated parameters: ${jobImpl.getParamsAsString()}</gel:log>

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

    However if I retrieve and echo the the parameters again (using the same code as above) I see they're blank.





  • 14.  RE: How to run parametrized Job through a process?

    Posted Feb 01, 2022 04:43 PM
    Hello again,

    I've dug a bit deeper. The line that pulls the original parameters back and echoes them to the log is this:

    <gel:log>Default parameters: ${jobImpl.getParamsAsString()}</gel:log>

    In my version of the script I added a couple of lines.

    The lines that set up the revised parameters and echo them back are now:

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

    The problem is that the second retrieval of the updated parameters shows that they are all blank, so it looks as if the call to set them up isn't working as expected.




  • 15.  RE: How to run parametrized Job through a process?

    Posted Feb 14, 2022 10:21 AM
    Edited by Jason McClellan Feb 14, 2022 10:21 AM
    Hi Paul,

    Thank you very much for working on this one.

    Did you get some chance to find the work around for 'set parameters' , as this line is not setting the parameter in the job?

    When I include below lines in code, in the logs I am getting the parameter value, but Job is not setting the parameter as before, it is running for all.

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



    Thanks,
    Jeevana.


  • 16.  RE: How to run parametrized Job through a process?

    Posted Feb 16, 2022 02:27 AM
    Hello again,

    Sadly, I couldn't get this to work. I did explore (in my own sandpit) doing direct database updates but that caused more problems that it was trying to solve, and it wouldn't have been a good workaround anyway.

    Paul


  • 17.  RE: How to run parametrized Job through a process?

    Posted Feb 17, 2022 12:07 AM
    Hi Paul,

    Thank you very much for taking some time and trying this out. :)

    Thanks,
    Jeevana.