cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to have an automatic cron job triggered when impex is run successfully

Former Member
0 Likes
1,230

Dear Experts,

I have a requirement where a workflow needs to be triggered when new products are added thru impex.

I know how activationscript functionality in WorkflowTempalte works. Limitation in that approach is a new product is attached to workflow only when it is created in backoffice product cockpit. I need the new product to be attached to the workflow when it is added thru impex.

Can someone please provide some insights into it.

Note: Iam using Hybris 1808 version.

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

andyfletcher
Active Contributor
0 Likes

I'm not totally familiar with the workflow engine but would using an impex afterEach work?

e.g. something like

 INSERT_UPDATE Product;code[unique=true];catalogVersion(catalog(id),version)[unique=true]
 "#%groovy% afterEach: workflowService.createWorkflow(workflowTemplateService.getWorkflowTemplateForCode('my-workflow-template'), impex.lastImportedItem, userService.getUserForUID('workflow-owner'))"
 ;1234;Default:Staged
 ;5678;Default:Staged

You need to make sure scripting is enabled for running the impex and legacy mode turned off impex.legacy.scripting=false. This should create a new workflow from the template 'my-workflow-template', owned by the user 'workflow-user' and attaching the product that was just imported.

If you need to have legacy mode enabled then you can do it with Beanshell too but it's just more verbose and harder to read.

 INSERT_UPDATE Product;code[unique=true];catalogVersion(catalog(id),version)[unique=true]
 "#% afterEach: ctx = Registry.getApplicationContext(); ctx.getBean(""workflowService"").createWorkflow(ctx.getBean(""workflowTemplateService"").getWorkflowTemplateForCode(""my-workflow-template""), impex.getLastImportedItem(), ctx.getBean(""userService"").getUserForUID(""workflow-owner""))"
 ;1234;Default:Staged
 ;5678;Default:Staged

Documentation around afterEach is a bit sparse but there are some examples here

https://help.hybris.com/1808/hcd/8bdf595b86691014b902e0974f71491a.html

A bit on scripting here

https://help.hybris.com/1808/hcd/640172cbde9149ab8eb818180544020a.html

Former Member
0 Likes

Dear ,

Thanks for your response. Well... this must be the OOTB approach for invoking a workflow. But I am getting below api error.

Error in method invocation: Method createWorkflow( de.hybris.platform.workflow.model.WorkflowTemplateModel, de.hybris.platform.jalo.product.Product, de.hybris.platform.core.model.user.EmployeeModel ) not found in class'de.hybris.platform.workflow.services.impl.WorkflowServiceImpl'

Opened the workflowserver.d decompiled WorkflowServiceImpl.class. But there is no method with such signature.

Any qucik help on this would be appreciated!

andyfletcher
Active Contributor
0 Likes

Yeah I hadn't tried this myself, it was just written straight into the comment.

The problem is that createWorkflow expects an ItemModel but the object returned from getLastImportedItem() is a Jalo type.

Try

 modelService.get(impex.lastImportedItem)

for the Groovy code

or

 ctx.getBean(""modelService"").get(impex.getLastImportedItem())

for the Beanshell version

Answers (2)

Answers (2)

Former Member
0 Likes

Dear , I have one more question. I would like to know impex is instance of which object in below line of code.

ctx.getBean(""modelService"").get(impex.getLastImportedItem())

When I run below line, workflow template is getting instantiated for each and every data row. If I have 10 data rows, 10 workflow templates are being instantiated. I want to have only one workflow instance for all 10 products. So I want to find other methods in the class of "impex" instance. Can you sare with me if you know.

Former Member
0 Likes

Dear ,

Yup you had mentioned on very first line that you were not familiar with workflow. Due to space constraint could not acknowledge that. Thanks for you update. Actually when I decompiled WorkflowServiceImpl, Idid not find any method that has three parameters. Now what I did is removed last parameter i.e workflow owner parameter. Now its working fine. Below is line of code.

"#%groovy% afterEach: workflowService.createWorkflow(workflowTemplateService.getWorkflowTemplateForCode('wfl_template_name'), modelService.get(impex.lastImportedItem))"

Thanks for your timely help. It actually helped me alot.