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

Triggering workflow

Former Member
0 Likes
8,386

Hi Experts,

I wanted to trigger a custom workflow during sales order creation/change. As I wanted to start workflow only based on some complex conditions I have decided to trigger it from user exit MV45AFZZ/USEREXIT_SAVE_DOCUMENT. Buidling this logic as workflow starting condition  or @ event linkage is not possible.

I can think of two options here to start workflow from user exit.

Option1: Start the workflow directly with the FM SAP_WAPI_START_WORKFLOW'. I doubt workflow triggerd in this way is not linked to the transaction and thus I shouldnt be able to see this from VA02/03?

Option2: Link my custom workflow to an event and triggering the event using  FM SAP_WAPI_CREATE_EVENT. Events CREATED/CHANGED for business object BUS2032 are triggered whenever sales order is changed/created. I am confused here about what event I need to link to my workflow and trigger? Do I need to create a subtype for 2032 and link my custom workflow and trigger CREATED & CHANGED event? As I am not changing anything for the business object my question is why should I create a subtype?

Much appriciated for any calrification on this,

Thanks,

Rams V.   

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Likes

Hi,

When faced with the issue to only trigger a workflow based on a complex logic. I would advise you to create a subtype of the business object and delegate that business object.

1. Create your own event

2a use a check function module to influence when you want a receiver for your event SWE2

2b extend the business object with an attribute that you can use in event-->wf conditions SWB_COND

You loose felxibility and control when you only use ABAP to control triggering of workflows

option 2b gives you the most control over your business processes.

Kind regards, Rob Dielemans

Answers (4)

Answers (4)

Former Member
0 Likes

Thanks a lot for your valuable inputs Rob.

I am very sorry still I am not able to understand why do we need both custom event and custom attribute? As this custom event is only triggered by me in the user exit why do I need this attribute?

Former Member
0 Likes

Hello,

I agree with you. I don't see the need for a custom event if you have a custom attribute. You can always turn off the link between the (existing) event and your workflow if there's a problem.

regards

Rick

Former Member
0 Likes

Thanks Rick. Hope this is my last question here ....I have checked few threads in SCN about setting virtual attributes in BO and use it in workflow start condition? Is it possible to set virtual attribue in USER exit and check the value in work flow start condition? Or we need to have data base field? ...if this is not possible I would rather go with custom event as i don't want to extend standard table for this field?

Or with the combination of check function module at start condition and EXPORTing a value in the userexit then IMPORTing it in the function module...

I wanted to use the best available solution without disutrbing standard sap functionality

Former Member
0 Likes

Hello,

A virtual attribute should work in a start condition, as long as it's not based on something that may not yet exist.

Give it a try.

regards

Rick

Former Member
0 Likes

Hi,

You are still going to use an exit to trigger an event. what I was trying to tell you is that you don't want that. You want to use standard event (or through change docs, status management, etc.) then using an attribute and conditions you can control whether you want to start a workflow or not.

Kind regards, Rob Dielemans

Former Member
0 Likes

I am not sure how I can set the value for virtual attribute I have created in my user exit. But I will give a go with FM SWO_INVOKE. Thanks guys.

Former Member
0 Likes

I agree. Keep it simple. No need for user exits or custom events.

Former Member
0 Likes

Hi,

you keep on mentioning the user exit.

If you have an event or change doc when you save this data then you won't need to bother fiddling around with cumbersome user exits.

My advise was to extend the business object, add an attribute(or attributes) link the event to workflow, and then use conditions with your new attribute to control the workflow.

This is straightforward Workflow consultant stuff, so please try and do it this way to get accustomed to these methods so that you can keep on using these methods in the future.

Kind regards, Rob Dielemans

Former Member
0 Likes

I completely agree with you Rob and I also wanted to do it in correct way. But how can I set the value of the custom/virtual/new attribue I have created? My assumption is that I need to do this in user exit?  Thanks a lot for your time sofar.

Former Member
0 Likes

I think this is explained in the Workflow tutorial on help.sap.com.

1. Swo1, type in business object, click subtype.

2. Swo1, go to delegate and delegate the business object with your subtype

3. swo1, edit, open attributes, click create, source virtual, name description and reference

4. position cursor on your attribute and click program.

5. code your own attribute (check help or other business objects programming to get accustomed to macros used for setting the virtual attribute

6. generate (follow instructions, you might have to also change release status)

7. Swo1, test your business object and see if the attribute is created with correct values.

8. swe2, link sap standard business object event to your workflow (it is delegated)

9. swb_cond find your linked business object-->event and add a condition with your virtual attribute.

10. test.

Kind regards, Rob Dielemans

Former Member
0 Likes

Thanks a lot for all your inputs. I just wanted to check if my understading is correct? I have two options here...

Option1 - I need to create a custom event for the deligated business object. Then I need to trigger this event from my user exit based on the triggering logic. And also define my workflow specifying the custom starting event.

Option2 - I need to add an attribute for the deligated business object. Define the workflow for the standard CHANGED/CREATED business objects with starting condition validating the custom attribute. Set the custom attribute in my user exit (I need to find out how to set this attribute).

Please clarify. Thanks.

Former Member
0 Likes

Hi,

Your best option is to :

first create a subtype and delegate the business object.

Create an event on your subtype, similar to changed/create

create a virtual attribute on your subtype, in the coding place your logic needed to validate the triggering.

Link the event to the workflow.

Use conditions SWB_COND for this linkage and include the attribute with logic for triggering the workflow or not ( attribute = 'X' or similar)

That way you have full control over your workflow and events. In the case of changes you can easily switch it on, or of. And maintenance wise it is easier to understand an extra attribute than it is to understand loads of abap in exits.

hope this clears things up.

Kind regards, Rob Dielemans

Former Member
0 Likes

Thanks every one for your valuable inputs. Using FM SAP_WAPI_START_WORKFLOW has any disadvantages compared to deligation with custom event?

Former Member
0 Likes

Hello,

You should avoid using SAP_WAPI_START_WORKFLOW. Use events when you can. There are many downsides, including not being able to disable it easily and it's harder for future support to find out how the workflow gets started. Also, the workflow template has to be set to General Task.

regards

Rick Bakker

Former Member
0 Likes

Hello,

Option 2 is the way to go, always use an event to start workflow when you can.

"I am confused here about what event I need to link to my workflow and trigger? Do I need to create a subtype for 2032 and link my custom workflow and trigger CREATED & CHANGED event?"

You only need a subtype if you're changing or adding something to the BO.

It seems to me you can just use the existing CHANGED or CREATED events, but there must be c omplication otherwise you wouldn't be asking, I guess?

regards

Rick Bakker / hanabi technology

Former Member
0 Likes

CHANGED & CREATED events for BUS2032 will be triggered anyhow when there is sales order change or create without me triggering them from user exit explicitly?

anjan_paul
Active Contributor
0 Likes

Hi,

  If I am not wrong, you only want to start workflow from User exit only based on some condition. Then if you trigger CHANGED & CREATED events for BUS2032, then you feel other workflow may trigger.

  If this is  the case, then there have 2 option. 1st option is you have to call the workflow directly usin FM SAP_WAPI_START_WORKFLOW. You don't have fear that it will not visible from VA02/03 servces for object. If your workflow having any container element of BUS2032 and in workflow basic data General Task has been maintain, then from VA02/03 your workflow will be visible in Services  for object.

2nd option is create a subtype of BUS2032 and create one custom event in subtype, and trigger that custom event to start your workflow, then no other workflow will trigger. That case also if you want to see the workflow overview in VA02/03, then your workflow must have container element of BUS2032 and in workflow basic data General Task has been maintain

Former Member
0 Likes

Hello,

Okay, now I understand.

I would not add code to create those or other events. I would extend the BO and use an attribute in the Start Condition (as suggested by Rob) or - if that didn't work - I would build it into the workflow itself.

regards

Rick Bakker