Tag Archives: K2 SmartObjects

ServiceObject definition does not contain method. ServiceObject:<>.Method: <>

Recently I encountered an issue while deploying a package from one environment to another. While testing the smartobject after the deployment, the following error message pop up :

Figure 1 Smartobject definition error

Reason: this error is thrown when the underlying method (tables or stored procedure in this case) cannot be found. This could be due to deletion or when the external component is not setup yet.

Steps to create the above scenario:

  1. Create a few stored procedures
  2. Refresh the Service Instance so that Stored Procedures are retrieved from the DB .
  3. Create the smartobjects from the instances.
Figure 2 SmartObjects generated from the create method

4. Now go back to the DB and delete one of the previously created Stored Procedure and add another one. Then refresh again (but do not create or generate the smartobject yet):

Figure 3 Newly retrieved Stored Procedures

As can be seen in the above image, there is a difference between the stored procedures. [dbo].[GetAnotherThing] does not exist and a new stored procedure [dbo].[GetSomethingFromTableDrop] is added. When the SmartObject GetAnotherThing is executed, the error dialog in Figure 1 will be shown.

Most of us when generating SmartObjects will use the Service tester to do so and select the Create method (Figure 4). When the Create SmartObjects method is used, smartobject with the missing method will still be there.

Figure 4 Create SmartObjects

The reason is that when this method is used, it does not delete any smartobjects since it is a smartobject creation/update method (Figure 5).

Figure 5 Creating SmartObjects Dialog box

Instead use the Generate smartobject method (Figure 6), this method will display the smartobject to be deleted as well besides the Create/Update method, BUT the drawback is that, it does not allow you to select the category to create the smartobject to:

Figure 6 Generate SmartObject dialog


Do not be mistaken and think that when external components are deleted, and doing a refresh of the service instances and executing the create smartobjects method will remove smartobjects that is to be deleted. Use the generate smartobjects method to help verify whether any smartobjects are to be deleted. Hope this helps someone!

Use SmartObject upload file to SQL

K2 SmartObject can read and store files into SQL table via its File property. Files to be stored into SQL table will be automatically converted to base64 encoded string and when retrieved from SQL, it will be automatically converted back to binary.

In this article, we will see how to setup and use SmartObject upload file to SQL and test the function in  K2 smartforms.

Use SmartObject upload file to SQL

  1. We start by setting up the SQL table. The column that will be storing the file content will be created as a nvarchar(max) type.Create table and file content column
  2. If the Service Instance to the SQL database (in this case “FileUploadTest”) has not been created yet, create it. If the Service Instance already exists, refresh the Service Instance. Make sure the new table and its properties are available.Create or refresh Service Instance
  3. Right-click on the [dbo].[FileUpload] Service Object and select Create SmartObject.Create Smart Object function
  4. Give the new SmartObject an appropriate Name and click on Publish SmartObjectCreate the file upload SmartObject
  5. You should find the SmartObject at the Category it is created above.
    The created FileUpload SmartObject
  6. Next, find the SmartObject in K2 Designer and Edit it. Edit the SmartObject in K2 Designer
  7. Select the property that is supposed to hold the file content (i.e. fileContent in this case) and click on the Edit button.

    Edit the SmartObject’s fileContent property
  8. Now, this is the most important step. Change the Type to File and click OKChange the fileContent property type to File
  9. Lastly, Click Finish to complete editing the SmartObject and you are done.Click Finish to save


  1. Now, to test the SmartObject, we will use the Generate View feature. Right-click on the SmartObject and select Generate Views.
    Generate the View from the FileUpload SmartObject
  2. Select the checkbox under Item and click OK. This will generate an Item View. Select to create an Item View
  3. Select the newly created Item View and click on RunRun the generated View
  4. In the form, fill in the file Name, select a file in file Content field and click Create. This will create the record in SQL. Try create a record
  5. Take note of the generated ID field value and check against the SQL table created earlier. You will find the newly created record with the file content. Verify that the record is created in SQL
  6. To verify that the file was indeed saved successfully into the table, refresh the View used earlier, fill in the ID field value and click on Read button to load the file. Click on the file to download it and make sure it can be open in the appropriate application. Use the View to download the file to verify that it's working as expected

And that’s all on how to use SmartObject to upload file to SQL.

Have fun!