Show TOC

How to Extend the Generated Code for WorkflowLocate this document in the navigation structure

Prerequisites

Make sure that you have a GWM Outlook add-in that calls an OData service based on SAP Business Workflow, and you are using the add-in as a Microsoft Outlook application.

Context

You can extend the generated code on completing and building of the GWM Outlook add-in template.

To extend the code, create a new proxy and extension classes for the service and implement the IValueHelpData interface, which is provided in your GWM Outlook add-in project.

Example

For example, you can extend the generated code by adding a Value Help to enable users to select the recipient when forwarding a task.

Procedure

  1. Right click on your Workflow task project folder (the folder has the name of the project you created in the New Project window), and select Add SAP Service Reference in the Solution Explorer of Visual Studio.

    The Add SAP Service Reference window appears.

  2. Choose Add Services, and click OK.
    The SAP Gateway Service Explorer window appears.
  3. Enter the URL of the userservice in the <Service URL> field, for example, http://<host>:<port>/sap/opu/odata/iwfnd/userservice/ and click GO.
    The collections of the userservice along with their properties are displayed.
  4. Click OK to generate the proxy and extension classes.
    Note The names of the proxy and extension classes that are generated are based on the name of the selected OData service in SAP Gateway.
    The selected service is added as a reference generating the proxy, and the extension classes in the Solution Explorer under SAP Service Reference folder.
  5. Once the project is generated, the classes for Value Help Picker are created in the following path: Start of the navigation path Solution Explorer Next navigation step Project folder Next navigation step Outlook Next navigation step Common End of the navigation path.
  6. Double click on the ValueHelpData.cs to open it for editing.
    The ValueHelpData.cs opens with the IValueHelpData Interface.
  7. Do the following to update the ValueHelpData.cs:
    1. In ValueHelpData.cs, create a class with a name of your choice to extend the IValueHelpData Interface. For example:
      class UserCollectionValueHelpData : IValueHelpData
          {
      
          }
      
      Note In this section we will use UserCollectionValueHelpData as the class name.
    2. Right click on the IValueHelpData Interface and select Implement Interface.
    3. Write the following code in the GetValueHelpData method to implement the ValueHelpData:
      public DataTable GetValueHelpData(string baseUrl)
              {
                  DataTable valueHelpData = new DataTable();
                  foreach (string propertyName in userservice.User.SAPPropertyAttributes.Keys)
                  {
                      PropertyMetadata propertyMetadata = userservice.User.SAPPropertyAttributes[propertyName];
                      DataColumn column = new DataColumn(propertyName);
                      column.Caption = propertyMetadata.Label;
                      valueHelpData.Columns.Add(column);
                  }
                  var serviceContext = new userservice.USERSERVICE(new Uri(baseUrl));
                  var serviceResponse = serviceContext.UserCollection.Execute() as QueryOperationResponse<userservice.User>;
                  foreach (var entity in serviceResponse)
                  {
                      DataRow dataRow = valueHelpData.NewRow();
                      dataRow[valueHelpData.Columns["firstname"]] = entity.firstname;
                      dataRow[valueHelpData.Columns["lastname"]] = entity.lastname;
                      dataRow[valueHelpData.Columns["username"]] = entity.username;
                      dataRow[valueHelpData.Columns["fullname"]] = entity.fullname;
                      valueHelpData.Rows.Add(dataRow);
                  }
                  return valueHelpData;
              }
      
      Note The names of the proxy, and the extension classes that are generated are based on the name of the selected OData service. The proxy name in the example mentioned in the code above is USERSERVICE.
  8. Double click on the ValueHelpFactory.cs located under Start of the navigation path Solution Explorer Next navigation step Project folder Next navigation step Outlook Next navigation step Common End of the navigation path to update it.

The ValueHelpFactory.cs class contains a factory method which initializes the appropriate value help collection class.

  1. Add a switch case specific for user service proxy, and user service collection, and then instantiate the appropriate value help collection class which was created in ValueHelpData class:
    internal static IValueHelpData GetValueHelp(string proxyName, string collectionname)
            {
                IValueHelpData valuehelpData = null;
                switch (proxyName)
                {
                    case "userservice":
                        switch (collectionname)
                        {
                            case "UserCollection":
                                valuehelpData = new UserCollectionValueHelpData();
                                break;
                        }
                        break;
                }
                return valuehelpData;
            }
    
    Note In the above code, use the same class name you provided when you created the class:
    valuehelpData = new UserCollectionValueHelpData();
  2. Use the ToolBox, and add a new button in the ForwardReserveForm to trigger the Value Help picker.
  3. Right click on the ForwardReserveForm.cs located under Start of the navigation path Solution Explorer Next navigation step Project folder Next navigation step Outlook Next navigation step Task End of the navigation path to open it for editing.
  4. Write the following code for the button event handler to trigger the Value Help picker:
    private void button1_Click(object sender, EventArgs e)
            {
    ServiceDetails serviceDetail = ConfigurationReaderHandler.Instance.GetServiceDetails("userservice");
    
    ValueHelpForm f4HelpForm = new ValueHelpForm(serviceDetail.Url,"userservice","UserCollection");
    
                if (f4HelpForm.ShowDialog() == DialogResult.OK)
                {
                    txtForwardTo.Text = f4HelpForm.GetSelectedValueHelp("username");
                }
            }
    
    Note Make sure that you reference the namespace as shown below in the ForwardReserveForm.cs: using SAP.IW.GWM.Common.Configuration;
  5. Run the project.
  6. In Microsoft Outlook, click on the Template Name (this is the name provided as the template name while creating the GWM project) tab on the menu bar to view all associated actions.
  7. Choose Forward to forward the task to another recipient.
    The Forward Task window appears.
  8. Click the ValueHelp button to fetch the list of users.
    The list of the users present in the SAP Gateway system is displayed.
  9. Select the user to whom you want to forward the task.