Optional Parameters will create fields with direction IN as method parameters. If those fields are defined as Optional, the corresponding method parameter will be optional too. Structures and Collections will be created as Properties even if their direction is IN and therefore by definition of SmartObject properties will be optional.
As from K2 connect version 4.6.5, all fields marked as Optional in SAP will be created as Optional in the Service Object as well. Note that this will only apply to fields where the direction is set to In. See image below:
Use the steps below as an example on how to use Optional Parameters. For this example we will use K2 Designer for Visual Studio 2012 to configure and publish the Service Object. We will then use the SmartObject Service Tester exe to execute a search function using the Optional Parameters.
1. Open K2 Designer for Visual Studio 2012 and create an empty K2 Project named Optional Parameters.
2. Add a K2 connect Service Object item to the project.
3. Click on Add Service.
4. Open the K2 Service Object Designer from the View menu.
5. Add the BAPI_EMPLOYEE_GETDATA filter to the BAPI Explorer.
6. Drag the filter to the new service as per the image below
7. Click on the Service Method to open the Method Designer.
8. Click on Clear All to clear the current selection of fields.
9. Select the fields as per the image below. Note that Return0 will be selected automatically.
10. Click on Go Back.
11. Click on the K2 blackpearl Settings icon. See image below:
12. Ensure that the Generate SmartObject option is enabled.
13. Click on OK and publish the Service Object.
14. Open the SmartObject Service Tester exe from C:\Program Files\K2 blackpearl\Bin.
15. Expand SmartObject Explorer.
16. Expand Optional Parameters.
17. Right click on the Employees SmartObject and select Execute.
18. The GetData method will be used to execute the search function.
19. Select a date for the Date0 property. This is required as the Date field is required from SAP.
20. You can now enter values in either the First Name, Last Name or both properties to execute the search.
21. Click on Execute. See image below for execution using the Last Name property.