Is it possible to run a Scheduled ScriptRunner Job from inside a Post-Function?

j.hoffmann February 19, 2021

I know I could just store the script in a file from within the "Script Editor" section of ScriptRunner, and then just use that for a Post-Function and a Scheduled Job, but I was wondering if there is a way to execute a scheduled job once from inside a Post-Function (so via Workflow Button) directly, as if you would press the "Run now" button on the jobs page manually.

Basically in pseudo code:

import com.onresolve.scriptrunner.scheduledJobManager

import com.onresolve.scriptrunner.scheduledJob

ScheduledJobManager scheduledJobManager = ComponentAccessor.getScheduledJobManager()

ScheduledJob scheduledJob1 = scheduledJobManager.getJob("JobThatDoesSomething")

scheduledJob1.run()

1 answer

0 votes
Joshua Sneed Contegix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2021
j.hoffmann February 19, 2021

Thanks for your reply.

I know how to write post-functions, and I read the documentation.

What I'm looking for is a way to import a custom Scheduled Job (that I created and runs every day) into a custom Post-Function script, and execute it from there (as if I pressed "Run now" on the Scheduled Job's page).

Joshua Sneed Contegix
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 20, 2021

Welcome!
Copy the script to the post function, modify as needed, and be done with it. I know this isn't the answer you want, but you're asking to do something that "isn't easily possible." It is possible through the Java API, like every function in the app, but you should asses how much effort you are willing to put in and the value of the output. Cheers!

j.hoffmann February 22, 2021

I see what you mean. I was hoping there to be a brief code snippet to do that, but I guess I can work with Script Runner's Script Editor too, and just have the code in a file as one central place, and then use that file as the job and the post-function.

Thanks.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events