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

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

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.

    306-step7
    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

Testing

  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!