Are you currently seeking a novel and efficient way to execute regular tasks on your SAP Commerce Cloud initiatives? Welcome! You've just stumbled upon the perfect blog.
My topic today revolves around Scripting - a game-changing approach to implementing CronJobs.
For the uninitiated, CronJobs refer to tasks that are executed at regular intervals. These tasks can range from anything like generating backup data and updating catalog contents to recalculating prices. In the context of SAP Commerce Cloud, implementing and maintaining CronJobs is integral to the day-to-day proceedings of any ongoing project. The caveat, though, is that modifying or creating a custom CronJob is traditionally a labor-intensive task and also can pack a punch on running Commerce instances, because you usually need to go through the following steps:
But we've got a great alternative — the process can get a whole lot simpler and quicker with scripting!
With scripting, you only need to implement the custom logic with scripting languages, drastically trimming down the bulk of the process and ceasing the necessity to restart servers and rebuild platforms. Now, you may be asking yourself — how is this possible? Let's navigate through the process together.
To kick start this venture, we'll need to create a script either directly in HAC of a running SAP Commerce Cloud, an illustrative screenshot of which can be found below:
or via ImpEx:
INSERT_UPDATE Script;code[unique=true];content
;myDemoScript;println 'Meet the power of Scripting in CronJobs, starting today: '+new Date()
Though my example might seem simplistic, it's important to remember: Scripting serves as your key to unlock the spring Context, accessing any available services. For example, you can directly send emails via emailService or execute any necessary database queries with flexibleSearchService, and many more.
Secondly, refer to the ImpEx code below to create a ScriptingJob instance:
INSERT_UPDATE ScriptingJob;code[unique=true];scriptURI
;mydynamicJob;model://myDemoScript
The ScriptingJob is a subtype of ServiceLayerJob, which implies you've already checked off a handful of steps necessary for a regular CronJob (i.e., steps 2-6 as mentioned above are now substituted by this single step).
Once this is done, we can promptly proceed to create a CronJob based on the scripting job. This can be achieved either directly through Backoffice:
or again, by utilizing ImpEx:
INSERT_UPDATE CronJob;code[unique=true];job(code);singleExecutable;sessionLanguage(isocode)
;mydynamicCronJob;mydynamicJob;false;en
And voilà! You've successfully created a CronJob that you can execute manually, assign to triggers, or execute directly with a script:
dynamicCJ = cronJobService.getCronJob("mydynamicCronJob")
cronJobService.performCronJob(dynamicCJ,true)
Possibly the best aspect of this process is the ability to modify the custom logic within the scripts even after implementation. Simply access the existing script object, amend the content and save your changes. The next time your existing CronJob runs, you'll find it echoing your latest script code, executing your newly-adjusted business logic.
To summarize, Scripting makes setting up a new CronJob much easier and faster. It also allows for easy changes to current CronJobs, making it ideal for quickly adapting to changing business needs.
And that wraps up my basic introduction to employing Scripting Support for CronJobs. Feel free to explore the help portal documentation on CronJob Scripting for more comprehensive information.
Additionally, you could expand your knowledge on the subject matter by attending our Expert Deep Dive Live Session: Scripting Support in SAP Commerce Cloud. Here's where you'll learn about the fundamentals of Scripting Support and its extensive applications across essential areas such as ImpEx, event handling, task engine, dynamic business process management, and even with the support of an expert trainer colleague in our team and a lot more demos.
Last but not least, don't forget to check out our array of Expert Deep Dive Live Sessions about SAP Commerce Cloud, expertly facilitated by the SAP learning team. We cover an expanse of exciting topics like "Integration APIs", "Hotfolders", "Interceptors", "Backoffice roles", "Dynatrace", "Composable Storefront", "System administrator essentials for SAP Commerce Cloud", and more.
Thank you for your time! Happy learning!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |