Triggering a work flow from CRM
Recently I came across a requirement to trigger a work flow from crm web ui component and would like to share within community, which can help others to achieve similar requirement.
Current example is based on CRM 7.0 EHP 2.
I have referred nice blogs written by Kiran Kumar Valluru:
http://scn.sap.com/docs/DOC-25493
Necessary configuration:
Necessary settings like RFC destination, Number ranges should be maintained in transaction SWU3
Scenario for this example:
User create / update an employee record and press on Submit button, it creates an workflow to his / her supervisor to approve.
Supervisor approve / reject the record and the decision conveyed to the user through mail.
First create a class (example: ZCL_WF_EMPLOYEE) which would trigger the workflow and would contain event, methods to process approve & reject decision.
The class should have interface IF_WORKFLOW assigned, which would automatically inherits BI* interfaces.
Please maintain necessary parameter in event, for example IV_EMPLOYEE_ID which you want to pass to work flow and can be linked to container. Event, methods should be public to be accessible from work flow.
Sample code to trigger workflow:
Please find attached text file Raise work flow for RAISE_EMPLOYEE_EVENT.
Screen shot of sample Work Flow :
Image may be NSFW.
Clik here to view.
Please find referred blogs for creating work flow. Approve and Reject are two activities which calls method SET_APPROVAL and SET_REJECT method.
Here keep in mind that both APPROVAL and REJECT methods are static; you can have instance methods but then it is required to have another activity to take back instance for class ZCL_WF_EMPLOYEE.
What is happening in CRM:
After user click on Submit button, on event handler of the button we should call RAISE_EMPLOYEE_EVENT of that class to trigger work flow.
Image may be NSFW.
Clik here to view.
Please find below sample code:
DATA: lr_wf TYPE REF TO zcl_wf_employee.
CREATE OBJECT lr_wf.
lr_wf->raise_employee_event( EXPORTING iv_employee id = <> iv_approver = <> ).
This would trigger an workflow task to the approver which can be found under Work list work center in Web UI.
Approver can click on the item or choose decision from the front screen itself.
Image may be NSFW.
Clik here to view.
After the decision mail would flow to sap Inbox -> documents, transaction SBWP in GUI.
How can I see inbox mailing Web UI:
Unfortunately from sap crm 7.0, user can not see Inbox -> Documents in CRM Web UI !
To resolve the problem automatic forwarding should be enabled through transaction SO13 for each user; so that Inbox mail forwarded as external mail like outlook.
Image may be NSFW.
Clik here to view.
Tracing work flow progress:
If you want to trace how far the work flow has reached (which level) or errors, transaction SWEL is useful.
On selection screen give event name and execute, you would see results -> double click to see work item.
if you click on work item you can see hierarchical log, click on Image may be NSFW.
Clik here to view.List with technical details to see detail description of message and graphical log to see how far is the progress.
Summary:
This blog is written on CRM point of view, please see refereed blog for workflow task creation and of course you can write to me anytime!
For viewing workflow task CT-WORKLST work center should be assigned to business role.
Courtesy: To my colleague Debdutta Dey for helping me to achieve the solution.