cancel
Showing results for 
Search instead for 
Did you mean: 

User mail Id determination using Rule

Former Member
0 Kudos

Hello Gurus,

I am very new to workflow.
I need help to determine agent's mail id at run time to be used to send mail notification to them, for that I have created a rule and created a FM to determine mail id.
I have created a container in the rule as agent_id, the same container I have created in workkflow and binding it with workflow.
but I have no idea what is the task I have to given and if needed to create what would be the purpose of it, as my purpose of getting mail id is fulfilled by rule and its container.
I can't activate the wf as its asking for task.
Any suggestion on this and is there any alternative solution.

Accepted Solutions (1)

Accepted Solutions (1)

I042439
Employee
Employee
0 Kudos

Hi Salil

Amalendu also has suggested a good approach.....from the method, he is calling a rule using 'RH_GET_ACTORS'.

For your other question, there is no need for macros to be called in the method, The method can have importing parameter as Notification Number (which will be passed from the task).

The method can then call the FM and provide the Notification Number to the FM and receive the email ID.

This email ID is passed back as an exporting parameter from the method, back to the class and then to the workflow.

Hope it clarifies.

Regards,

Modak

Former Member
0 Kudos

Hi Modak,

I understand that but could you clarify that how it can be achieved.

Below is the code for your reference

begin_method mail_id changing container.

DATA: l_qmnum TYPE viqmel-qmnum,
          l_notification TYPE swc_object,
          mail_id TYPE ad_smtpadr.


swc_get_element container 'Number' l_qmnum.   

            
CALL FUNCTION 'ZFM_DETERMINE_MAIL_ID'
   EXPORTING
     i_qmnum  = l_qmnum
   IMPORTING
     email_id = mail_id.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


swc_set_element container 'Email_id' mail_id.

end_method.


Here I have Created  Notification as import parameter and EmailAddress as an export parameter for the method.

When I am not using Macro to get the value of Container in l_qmnum and directly using Notification instead to be passed to the exporting parameter of ZFM_DETERMINE_MAIL_ID then its giving an error saying Notification is not defined.

I have another doubt, if I am defining an element in the container of the task which will call this method, then it should be named same as of the parameters used in Method for eg; EmailAddress and Notification.
How the system will understand that for given element in the container I need to populate the value from the parameters from Method.

Below is the screen shot for parameter defination

I042439
Employee
Employee
0 Kudos

Hi Salil

I usually work with Class Objects and hence thought the same with you.

yes, the name should be same.

Here you can use macros as:

swc_get_element container 'Notification' l_qmnum



and


swc_set_element container 'EmailAddress' mail_id.


Sorry for confusing you here.


regards,

Modak

Former Member
0 Kudos

Hi Modak,

I did exactly the same before.
Can you please let me know if its possible to debug the method which I am using in the task.
Its still not determining the email id
I have rechecked all the bindings, it seems to be perfect.

Former Member
0 Kudos

Hi Modak,

Here is the screen shot for your reference where you can see that Notification No is getting assigned to the task  but the Email id is coming as empty.

I042439
Employee
Employee
0 Kudos

Hi Salil

Can you send the screen shot of binding from Task to Method?

Regards,

Modak

Former Member
0 Kudos

Hi Modak,

Thanks a lot for your time and help.
I have found the issue, its working fine now.

The FM was going to dump because of the mandatory parameter which I was not using, and I was running it in batch mode so didn't realise it, I noticed later that in ST22 and found the issue
Thanks again for help.

Regards,

Salil Bagchi

former_member185167
Active Contributor
0 Kudos

Hello,

"need help to determine agent's mail id at run time to be used to send mail notification to them"

Since you are new to workflow I'd like to point out that all of the above hassle was unnecessary.

You should use Extended Notifications to send emails to users notifying them of workitems in their inbox. Set it up once and it will do the job for every workitem in every workflow.

Even if you don't use Extended Notifications, it is much easier to send an email to the SAP user and let SAP figure out what their email id is, instead of trying to figure it out yourself.

regards

Rick Bakker

Former Member
0 Kudos

Hi Rick,

Thanks for the information, but my requirement was to send mail to the users, whose mail id will be maintained in custom table and they will receive mail in their lotus notes and not in workplace inbox, for that purpose I had created FM which was returning user mail id's from custom table.

Regards,

Salil Bagchi

former_member185167
Active Contributor
0 Kudos

Hello,

There is no need for a custom table, just associate those email addresses with the users within SAP and SAP will find it when you send a mail to the user.

regards

Rick Bakker

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

     Steps to find mail id from a rule to your workflow.

Here, you have to bind workflow to task, task to BOR, from BOR you have to call the rule (which will have bindings between rule container and Z-Function Module)

Simple steps:

Assumptions: You have PERNR value and you need to find mail id.

1. First create a rule - create two elements in rule container - PERNR and mailid (set both of them to import and export)

2. Create a Z-FM - in it get the container element PERNR using SWC_GET_ELEMENT.

    Write your logic ; and then using SWC_SET_ELEMENT set the mail id in ac_container (in tables parameter in your Z-FM)

3. Then create an activity in your workflow, in that create one task.

4. In task container again create same two container elements.

5. Create one Z BOR object and method - assign it to task.

6. In Z-BOR object-method, write the following code.

SWC_GET_ELEMENT CONTAINER 'PersonnelNumber' lw_pernr1.

lw_act_role(2) = 'AC'.

lw_act_role+2  = '<rule no>'.

CALL FUNCTION 'RH_OM_ATTRIBUTES_CONTAINER_GET'

  EXPORTING

    ACT_ROLE        = lw_act_role

  TABLES

    ACTOR_CONTAINER = lt_act_container

  EXCEPTIONS

    OTHERS          = 0.

CALL FUNCTION 'RH_GET_ACTORS'

  EXPORTING

    ACT_OBJECT      = lw_act_role

  TABLES

    ACTOR_CONTAINER = lt_act_container

    ACTOR_TAB       = lt_actor_tab

  EXCEPTIONS

    OTHERS          = 0.

IF NOT lt_act_container IS INITIAL.

<your logic - get the container value for element 'mailid'  - created container element>

SWC_SET_ELEMENT CONTAINER 'mailid' lv_mailid.

ENDIF.

7. create proper bindings between workflow container and task container (whose element values BOR object sets in the above code)

8. You got your mailid in workflow container!!!

I042439
Employee
Employee
0 Kudos

Hi Salil

Why did you use a rule for this? Any specific reasons?

Why not use a BO/Class Method, call the same FM, and call that Method in a Task (type Activity) as a background step.

Input -> agent_id

Output -> Email ID (in a  workflow container)

After that use a mail step and use the email in addressstring of the mail step.

There are other ways too, however, since you are new to workflows , I would suggest the above simpler version.

Regards,

Modak


Former Member
0 Kudos

Hi Modak,

I will try that step as well using Method, but I wanted to know how it can be achieved using Rule only with the FM which I have created for determining the mail ID.

I have a confusion here, I am assigning mail id to object id of structure SWHACTOR used in table parameter in the FM.
How Can I export this objid to be used in container for Rule which Later I can bind to container of workflow to be used?

I042439
Employee
Employee
0 Kudos

Hi Salil

Rules can only have importing parameters and no exporting parameters.

Your approach to use a rule in a mail step will not work - the mail step only takes an expression from the workflow container, org object and an email.

Rules are maily used for Agent determinination for dialog work items - which is not the case here,

Regards,

Modak

Former Member
0 Kudos

Hi Modak,

I have created a a task and done all the bindings..
in the method of the task I am using the same FM.
Standalone that FM is working fine but by workflow, its not determing the mail id.
Might be the problem with Macro calling for Container, Could you please write a sample code for my reference to bind the content in the container with Macro.

I042439
Employee
Employee
0 Kudos

Hi Salil

Sorry... I should have mentioned more clearly....using the same code means the logic.....however you have to adjust the signature.

So the chain would look like this:

1) Workflow calls a task from the activity step

2) In the binding, WF passes the agent id to task and receives the email ID from task

3) The Task calls your custom BO/Class method and passes necessary data / receives necessary data from the method

4) The method calls the revised FM (signature has the agent id as importing and email as the exporting parameters).......remove macro calls from the method and use the imported parameter to get the email.

If you want to avoid coding, here is an alternate way:

1) Send the email to 'Org Object'and specify the user ID (variable containing the user ID)

2) SO16 -> mail system -> select 'Send to User's Home Address'

3) Ensure that  user email is maintained in User Master(SU01) or HR infotype 105  (if exists)

4) When  workflow will send the email to Org Object -> user....it will also send to email address of the user....will pickup based on settings from SO16

Please note SO16 is system wide.

regards,

Modak

Former Member
0 Kudos

Hi Modak,

Thanks for the help, but still its not working.
I will attach screen shot and I am not getting where I am missed.

1) Workflow calls a task from the activity step

2) In the binding, WF passes the Notification No. to task and receives the email ID from task

3) The Task calls the custom BO/Class method and passes necessary data / receives necessary data from the method.

4) The method calls the revised FM (signature has the agent id as importing and email as the exporting parameters).......remove macro calls from the method and use the imported parameter to get the email.

Here I have doubt in 3rd and 4th point.
I am using Notification No to determine the email id instead of Agent ID by passing the notification no in FM in import parameter and getting email address at export Parameter.

Now I have to pass the notification No to the FM  for that purpose  I have created parameters of that particular method.

The notification No as export parameter and Email id as import Parameter.
Now I am using Macro in the program of that method to get the value of Notification no and then using that to determine the mail id through FM, and then using macro to assign the mail id back to the container.
I think here I am doing something wrong.
Please clarify if I am not going to use the macro in the method, how I will set the value of email id back to container.
After Executing the WF, I can see that Notification no is getting assigned to the container of the method but email id is empty