on ‎2018 Oct 05 1:09 AM
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!
Request clarification before answering.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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!
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.