Skip to main content
Nintex Community Menu Bar

I have a form that has a smartobject, SO_PrimaryDocList, view to attach documents.  Multiple attachments can be made and through the Smart Object Tester this piece is working as expected.

Once in the workflow, I create a Document Set based on "Project Name", this is data entered by the user on the form.  Once the document set is created I need to upload all attachements to it.  If I'm only dealing with 1 attachment, it works perfectly, it's only when I need to loop through multiple. 

In general, I'm unsure how this is supposed to work, any help would be appriciated. 

 

Here's what I have set up now:

1. On the activity, I have set a Destination Rule to Plan per slot, To determine how many slots: SO_PrimaryDocList.GetList.ID (inputting a created ProcessID, filter to make sure ProcessID in Flow matches ProcessID in SmartObject & Returning ID) I'm returning all results that match filter.

2. On a SmartObject event I use SO_PrimaryDocList.GetList.  Input the ActivityInstanceDestID and Return the Content and FileName to variables I created with scope = activity.

3. Another SmartObject event using a SharePoint service Object, SO_SP_Primary_Documents.Upload Document.  Input is the FileName and Content of the activity variables.

 

I think I need save #2 to an array of some sort?  Do I have to do this step?  Can one SmartObject talk directly to the next?

Looking at the instance data in workspace, it creates the correct number of slots, but fills it all with the same information.

Hi Jamie, I think you are on the right track. One thing to be careful about when using the "Plan per slot (no destinations)" rule is that you need to check that all activity instances are complete before you exit the Activity. To do this add a succeeding rule to the activity: All of Activity Instance Destination -> Status = Completed.

 

When you look at your viewflow for a process instance, you should be able to see how many activity instances were created, when they started and finished, and what the activity data fields contained. If you see that one activity never finished then this may be your issue.


Thank you for your reply! 

I have looked at the activity slot data and it writes the same information over and over again in each slot.  It's failing before exiting the activity, but I will add the exit rule to make sure when I do get this working it won't exit early.

 

Any idea about it writing the same information over and over again in the slots?


I believe when using plan per slot, the data per slot will be stored in the "Activity Destination Instance > Instance Data" field.


 



 


This will be stored as a string I believe, as such you may need to use a Fx function > Conversion > To Integer if you are passing that ID field in the 'Instance Data' to your Smartobject call that would retrieve the file. 


 


If you are on K2 blackpearl 4.6.11, you may be able to achieve this same behavior with the new 'Create Reference' and 'For Each' event.


 


Tin -

 

Of course there's an easier way in the next version than what I'm on!  I'm on 4.6.10.

I have changed the ID to an integer.  I think its interating through everything because the error I get in workplace is the following:

 

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Exception: File Upload failed - File already exists. at SourceCode.SharePoint.WebServices.K2SPFunctions.K2SPFilesFunctions.UploadDocument(SPObject spObject, String listNameOrTitle, String folderURL, String contentType, String fileName, ByteB] oByte, Boolean overWrite, String metaDataDetail) at SourceCode.SharePoint.WebServices.K2SPFunctions.K2SPFilesFunctions.UploadDocuments(SPObject spObject, XmlNode items) at K2SPFiles.UploadDocuments(XmlNode items) --- End of inner exception stack trace ---

 

I now get the Instance ID which you said pulls the file - but what field has the file for me to transfer to SharePoint?  Right now I'm using fields I created under activity and I think each loop through writes over the last.  That's why I have the right number of slots, but the same information is in each slot. 

I "think" the "for each" should grab the first doc with smartobject, then pass to the next event and upload the doc, then go back and grab the next doc with the smartobject and next event upload it.  But it doesn't work that way.  It grabs all the doc information with the smartobject before it moves on to the upload.  I think that's why I'm writing over the same data and why 1 document works, but anymore and it errors.

 

Any thoughts?


Could you perhaps attach a screenshot of which field you are using?  Is it the:


 


Activity Instance Destination > ID field


or


Activity Instance Destination > Instance Data field


 


Sure!  I tried to get every screen in the shot.

 


I submitted a ticket to K2 to get the resolution on this.  It was, as I suspected, how I was storing the data.  This is how you iterate through a smartobject:

 

1. The activity destination: Plan per slot, use the get list method of the smartobject and return its ID.

2. Use a smartobject event to 'get list' of the smartobject: Input mapping is the "To Integer (ActivityInstanceDestInstanceData)"  That's the ID captured in step 1.  Return the values you want into SCOPE = DESTINATION fields.  This is where my issue was.  You create this field by creating an ACTIVITY field that is NOT SHARED.

3. Use those fields as needed.  I need to upload attachments to SharePoint so I'm using the Out of the Box SharePoint Document Event in the same activity. 

 

Note: this all has to be done in the same activity as you are only storing values at that level.

 

I hope this helps anyone else who is in search of how to do this!


Hi Tin

 

We are facing same issue while uploading file to sharepoint document library. Can u please provide as a sample project ? It would be a great help to us.


 Hi All,

 

I am looking for solution to below scenario.

 

1. SmartObject will be created for employee.

2. While submitting employee details, mutiples attachments  will be added on smartform using file attachment control.

3. On single click of submit button, form data needs to be pushed into sql while attachment needs to uploaded into sharepoint library by creating one document set per employee.

 

Can you please explain steps required to achieve this using k2 workflow or send me solution at mailasifmomin@gmail.com

 

 

Thanks

Asif


Hi!

You are attempting the same thing we are doing.  I will try to explain what we have done.  All names are only suggestions, please follow your naming conventions.

  1. On the form - create a smartbox smartobject called something like SO_EmployeeAttachments. 
  2. On SO_EmployeeAttachments: Create at least 2 fields in addition to the ID field: EmployeeSubmissionID (type = text) & AttachementFile (type = File)
  3. On the form - create a form level variable to hold a unique ID for this instance and call it EmployeeSubmissionID (if you don't already have something like this).  I'd concatenate the Employee Name, Employee number, and date/time of submission.
  4. When submit is clicked transfer all data needed, with your EmployeeSubmissionID to your existing SmartObject AND using a get list method on the attachment view, upload your files to new SO_EmployeeAttachments with the EmployeeSubmissionID.  Note: the Type = File will contain the file name and content.

 

In the workflow:

  1. Create an Activity called: Create Document Set. 
  2. Add a smartobject event (out of the box SP, or  your own) named Create Document Set.  Use the smartobject to create the document set on your SP site.
  3. Create a DIFFERENT activity called Upload Documents to Doc Set
  4. Set the slots on the activity to use the get list of the SO_EmployeeAttachments to determine number of slots needed.  Filter based on EmployeeSubmissionID (let me know if you need more detail on how to do this)
  5. Add a smartobject event (SP or your own) called Get Document Data.  Set it to use the get list method on SO_employeeattachments filtering on the EmployeeSubmissionID (same as the slot data)
    1. Your input mapping will be the activity instance destination data (ID gathered at slot creation) converted to an integer.  It will look something like this: To Integer(ActivityInstanceDestInstanceData)
    2. Return Mapping - Create 2 Activity Level variables, one called ACT_AttachmentContent the other ACT_AttachmentName and transfer the content and name into them.
      1. This is where I made my original error - the ACT_AttachmentContent needs to be Binary and Shared needs to be unchecked. ACT_AttachmentName is a String and Shared is unchecked.
  6. Add another smartobject event to the Upload Documents to Doc Set Activity (SP or your own) to use the create method on your SP doc set.
    1. Input Mapping - use your ACT_AttachmentContent and ACT_AttachmentName to map to the right fields.
    2. No return mapping is needed.
  7. Final Step - clean up your SO_EmployeeAttachments by using slots and the delete method filtered on the EmployeeSubmissionID.

 

Let me know if you want more detail on any of the steps above.


Hi Jaime,

 

On call of Get Document Data step I am getting two duplicate records instead of two different record.

Could you please let me know what might causing this issue. 

 

Thank you,

Kaushlender


Reply