K2 List Attachment cannot download file if stored procedure contains parameters


Badge +3

Hi All,

 

When retrieving attachment list from database, i realize that k2 list view does not work if the stored procedure contains parameter.

 

For example,

 

I retrieve attachment based on transaction no.

Stored procedure work ok, but when turn to k2 list view, the attachment cannot be downloaded.

 

It only works if all the attachments are retrieved and then filter by transaction no in k2 list view.

 

But this will cause the loading time getting slower if more and more attachments.

Any ideas how to solve this?

 

Thanks & Regards,

Kyo


14 replies

Badge +10

HI,

 

This shold be possible without having to as yo said load everyting and the filter it. I had a similar problem before when I wrote a custom API for attachments. It had the usual create, update, delete , list by requestId (transactionId) etc method. It would load fine but when you click the item it would not download. K2 support later said that the ap needed a read method. So you need a method that takes the "id" of the attachment and then reads it from the database. The list method and the read method must be on the same smartobject that the list view is based on, if that makes sense.

 

I am not sure if this is the case with your problem. Please provide more information on your implementation.

 

Hope that helps

Userlevel 5
Badge +16

Hi,

 

Can I see your stored procedure?

 

 

Badge +3

Hi,

 

Basically my stored procedure just get the attachment data from table.

 

i want to get the list of attachment data based on parameter (Transaction No in my case).

But whenever i use stored procedure with parameter (Transaction No), when loading the k2 list, the attachment can be retrieved but when click on the list to download the attachment, no respond.

 

The workaround is to take away the stored procedure parameter (in this case get all attachment from the data), then when loading in k2 list view, filter the list by transaction no.

 

But when the number of attachment is increasing, the loading time will getting slower.

So i m stuck here.

 

Thanks & Regards,

Kyo.

Badge +10

It may also be that you are not returning the correct data type. Try changing the property of "file" (whatever it's called in you one) field in the smartobject to a file type.

 

Badge +3

Hi,

 

It is already "file" datatype in my smartobject.

Temporary this cannot be solved as k2 consultant said that it is k2 bug.

 

You can try to add parameter in your stored procedure (Select attachment from attachment table).

The list view will select the attachment but when you click on the list, the file cannot be downloaded.

 

Thanks & Regards,

Kyo.

Badge +12

Hi Kyo,

You are right that this has been logged as a bug but has already been addressed in 4.6.10. May I know which version are you running on? I believe a fix for SF 1.0.7 is available via Support channel. You may also consider injecting a javascript/jquery to allow for the file to be downloaded with the list view item clicked.

Thanks

Badge +3

Hi Ajo,

 

I am using 4.6.8. As i know when i click on the list to download, javascript:void(0) appears at the bottom.

 

How am i going to make the file downloadable using jquery?

 

Thanks & Regards,

Kyo.

Badge +10

What database do you use to store your attachments. I am not sure you can make direct databae calls from jQuery. According to an post in stackoverflow

 

"The best thing you can do is to issue an AJAX request to a server and then execute this query using a server side code."

 

Would it not be easier to just write a .net service object. Just write methods to read, write, list (by transaction id), load, etc 

Badge +12

Hi Kyo,

Here's an example I tried on my end. I have a stored procedure which has a parameter and gets files from a custom db. The table  which stores the files has the following properties:
ID - int
FileContent - nvarchar

1. I created a smartobject for this table and use it's Read method created by the SQL service

2. On your list view, add 3 controls:
Hidden ID - data label
Script - data label
Hidden File Attachment - file attachment

3. On list item click, add the following actions:
a. transfer data
b. on [smartobject] execute it's Read method
c. transfer data
d. transfer data

4. The first transfer data, the ID of the item clicked will passed to the Hidden ID data label

5. For the smartobject action, we will configure it such that when the list item is clicked, the file will be loaded to the Hidden File Attachment. We will use the value of the Hidden ID data label as parameter for the Read method11484i6E75961A747C2AEA.png

8. The last action serves as a flush so it will work for other items in your list:
Script - [empty]

9. Hide the 3 controls added, save then run the view

Hope this helps.

Thanks!

Badge +10

Thanks Ajo,

 

That has given me an idea on how to make make automatic dowloads. User clicks a button to download a document. That in turn calls a smartobject method to get the document and put it in a file attachment control. At the same time I transfer the onclick script for that control. And it downloads it. It seems you have to clear the script afterwards otherwise when you clcik the button again it wont work. Before, I had to show a button and then a subview which had a file control and the user had to click on the file control to download, now they just click a button and it downloads. Much more intuitive than before.

 

I always thought the ID of a control would change so never looked into injecting any jquery. However it seems on the same machine after a few tests , it seems it keeps it's ID. Just wondering if you know, when you take a form where you have hardcoded the control Id and deploy it to another envirnment like Productio or Test, does this ID change.

 

 

 

Badge +3

Hi Ajo,

 

I had tried the steps you had mentioned, but still not successful.

I think there are some steps that i miss out.

 

1) The smartobject only contains 1 read method? It does not work if do not have list method as i need to show the list. I had created two methods in the smartobject by using same stored procedure but just change the method type in smartobject (1 is list, another 1 is Read). List method to generate list and Read method to execute when "list executes item click"

 

2) When i click on the list, i had pass the attachment ID to the hidden ID data label, then using Read method to get the hidden attachment content to the hidden file control. In this case, my attachment content format in my table is <file><name></name><content></content></file> instead of file path. But i cannot see any data pass to the hidden file attachment control.

 

3) Is the script same for all? Just passing the same script to hidden script data label everytime click on the list?

 

Thanks & Regards,

Kyo.

Badge +12

Hi Kyo,

  1. Have you tried creating a smartobject for the table which stores your files? I let the SQL service generate the Read method for me so I can use it to populate the hidden file attachment
  2. Are you using the hidden data label as a parameter for your Read method? Try to hardcode the ID first when you configure the Read method and see if the hidden file attachment gets populated
  3. The script depends on the label for value of the hidden file attachment control. You just need to replace this: 
    $('label[for="<this part>"]').click()
    You can determine the value through the developer tools of your browser. I use Chrome since it’s easier

Thanks!

Badge +12

Hi s0m3one,

I honestly haven't tried this but I don't think the values of the HTML elements of a form should change after being deployed from one environment to another. I am not too sure myself so it's best to test this out :)

Thanks!

Badge +10

Hi Ajo

 

I tested it out by packaging and deplying to a new environment and it does infact keep its value. This is excellent, because now i can start injecting all sort of scripts which i had just written off before since i thoung the ID of a control (since it was generated dynamcally) would change.

 

@Update: After further testing it turns out that the ID's of controls do change if you deploy it to another environment. My first test must have been a freak accident because afterwards I could never keep the same control Id when deploying to antoher environment. 

 

Thanks again

Reply