Attachments

  • 23 August 2012
  • 8 replies
  • 9 views

Badge +1

I have a SQL Table that has the varbinary(MAX) data type but when I bring this table in as a SmartObject I do not see this field and I do not understand why.  What I was hoping for was to be able to attach a single attachment during a creation of a record.  However, without seeing this data field I am not sure how I would go about that.  Any ideas on what I may be doing wrong?


 


Thank you - Paul


8 replies

Badge +5

Do you know that you can give a column the type of "File" when you add a column to a SmartObject?


Or does that not work like you want?

Badge +1

I do and did try this but there appears to be various SQL data types that are not support by K2 SmartObject Service, list provided below that Tech Support gave me.  Still waiting to find out what one can do when they want to add attachments through this application.


The SQL Server Service does not support the following SQL Data Types: 


-TimeStamp 


-Image 


 


-SQL_Variant 


-Binary 


-VarBinary 


-Numeric 



 

Badge +4

Hello,


K2 serializes attachments as an XML string in order to store them in the DB. The SmartBox service uses an "nvarchar(MAX)" data type to store this data. 


We did the same in our custom DB tables and stored procedures, and it works. From Visual Studio, when creating your smartobjects, you should see your "nvarchar(MAX)" field. When creating a new K2 property mapping to map to this field, make sure you select the "File" datatype. This mapping will ensure K2 writes XML to include the file name AND the serialized file itself.


HTH,


Tyler

Badge +1

After rebuilding the SmartObject and using the SQL Data Type nvarchar(MAX) I am able to attach attachments.  I guess I needed to rebuild the SmartObject...?  Oh well it works now, whew! 

Badge

Hi,

 

May I know if you have any issue on retrieving the attached file? I'm having object reference when reading from the File column with xml tagging <collection> not <content>.

 

Thanks!

Userlevel 5
Badge +18

Hello K2meme,


 


I assume you are able to add/load attachment with <content/> XML in the DB?  But not load any item with <collection/> XML?


Then it is likely that previously attach filed were not converted/stored in the DB with the proper format; as such retrieving them is no longer possible.  If the K2 'File' property is expecting the <content/> XML on Load/GetList method.

Badge +2

I ran into similar issue another day and it took me awhile to figure it out.  The most important part is changing the data type in the SmartObject once it's created.  

 

DB column: XML

K2 default mapping: MEMO

K2 working mapping: FILE

 

If you leave it with Memo, it will only save the file information, but not the content.  So everytime you publish or override an existing SmartObject, REMEMBER to change the file type from K2 Designer or Studio.

 

If stored with default MEMO data type:

<collection><object><fields><field name='FileName'><value>Myfile.pdf</value></field><field name='FilePath'><value>asdfdfdsfdsMyFile.pdf</value></field></fields></object></collection>

 

When changed to FILE data type:

<file><name>MyFile.pdf</name><content>//5VAFMARQAgAFsAQgBUAF0ADQAKAEcATwANAAoASQBOAFMARQBSAFQ</content></file>

Badge +1

I tried the suggested settings that changeus suggested and now I am getting a "Object reference not set to an instance of an object." in my workflow.  Did anyone else get this error and does anyone know of any other ways of storing and pulling files from a SQL table?


16592i9CB7BB4FB5BD4F17.jpg
16848i0828D3E0035B7A74.jpg

Reply