Use Scripting Job in SAP Hybris

Hybris Logo

1. Overview

The scripting job is a very particular job in Hybris, it gives you the possibility to run scripts of type Groovy, BeanShell or Javascript as a cronJob.

Scripting job in Hybris

  • Script : is a statement in Groovy, BeanShell or Javascript, in Hybris it’s an instance of the ScriptModel class.
  • Scripting Job : is an instance of the ScriptingJobModel, It takes as a parameter the URI to the script, the URI could use http, https, ftp, file, classpath or model.
  • Cron job : the cron job is an instance of the CronJobModel, it takes in parameter the Scripting Job.

In this article, I will show you how to create a scripting job in Hybris.

2. Scripting Job in action

2.1. Script

First, let’s create our script Groovy, via the impex.

INSERT_UPDATE Script;code[unique=true]	;scriptType(code)	;content
					;helloWorldScript	;GROOVY				;println "Hello World!"

2.2. Scripting Job

A scripting job is an instance of the ScriptingJobModel, the scripting job will be referring to our script helloWorldScript using URI of type model.

INSERT_UPDATE ScriptingJob	;code[unique=true]		;scriptURI
							;helloWorldScriptJob	;model://helloWorldScript

You can use any URI protocol (http, ftp, file, classpath…) you want for the scriptURI.

2.3. Cron Job

Last and not least, create an instance of the CronJobModel and attach to it the scripting job helloWorldScriptJob.

INSERT_UPDATE CronJob	;code[unique=true]			;job(code)				;sessionLanguage(isocode)	;sessionUser(uid)
						;helloWorldScriptCronJob	;helloWorldScriptJob	;en							;admin

Start the cron job helloWorldScriptCronJob manually from the HMc/Backoffice, or attach a trigger to it.

Start scripting Conjob from hmc in Hybris

If everything goes well, you should have a log similar to this :

18.09.25 00:22:39:247	INFO	### Starting executing script : model://helloWorldScript ###
18.09.25 00:22:39:247	INFO	Hello World!
18.09.25 00:22:39:247	INFO	### Finished executing script, returned script result = null ###


4.8 4 votes
Article Rating
Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Newest Most Voted
Inline Feedbacks
View all comments
5 years ago

brief, simple and useful, thank you (y)

Reply to  Ayoub
5 years ago

simple and perfect explanation

Reply to  Mouad EL Fakir
5 years ago

perfect ! thanks!

5 years ago

what is the use of scripting?

Lahcen Zbair
Lahcen Zbair
5 years ago

Very interesting, will keep in mind … i was asking myself about some benefits, and I think there should be a lot: – Runtime extensibility: you can schedule technical / functional task while your Hybris is up an running (to be done in a moderate way, otherwise will end up with scattered codebase ) – Open the door to other languages (I know you have already Scripting console (HAC), but here you can do it in a periodic-basis) – It could be a good candidate to add orthogonal (ie not linked to a specific business case) functionality; exp: Schedule a… Read more »

Reply to  Lahcen Zbair
5 years ago


5 years ago

Hello, in a scenario where i want to enter a script as below, how to handle ; and line separators ??? // Create a temporary file for the demo file = File.createTempFile(“stuff”,”.tmp”) file.deleteOnExit() pw = new PrintWriter(file) pw.println ‘This is line 1’ pw.println ‘This is line 2’ pw.close() // Create the email email = de.hybris.platform.util.mail.MailUtils.getPreConfiguredEmail() email.addTo(‘[email protected]’) email.subject = ‘Important stuff attached’ email.msg = ‘Here is your attachment’ // Create an attachment that is our temporary file attachment = new org.apache.commons.mail.EmailAttachment(); attachment.path = file.absolutePath attachment.disposition = org.apache.commons.mail.EmailAttachment.ATTACHMENT attachment.description = ‘Stuff’ = ‘stuff.txt’ // Attach the attachment email.attach(attachment) // Send the… Read more »

2 years ago

thank you!

Would love your thoughts, please comment.x