I am new to Appian. Still learning the basics.
I have two tables
1. Attachments - for adding attachment relate details like fileId,fileName, fileExt, fileSize etc and
2. AttachmentDetails - for description, comments etc
Below is the requirement -
When i upload a document I save them to the attachment table with attachmentDetails primary key (attachmentDetailsId)
After the documents are saved in the attachment table I need to save the attachment tables primary key (attachmentId) to the attachmentDetails table
The problem is i am not sure how to update when there are multiple attachments.
For Example - If i upload 2 attachments and update attachmentDetails
Attachments Table
Attachment Details Table
I will first save the 2 attachmentDetails (array) to the db first. (at this point attachmentId will be null and I will have the attachmentDetailsId's)
Before saving the attachments to the table i need to map each attachment with attachmentDetailsId. How do i map attachmentDetailsId-1 with first attachment and attachmentDetailsId-2 with second attachment?
After I map the above I will save them to the attachments table (at this point I will have the attachmentId's)
How do i now map attachmentId-1 to the attachmentDetailsId-1 and How do i now map attachmentId-2 to the attachmentDetailsId-2?
Discussion posts and replies are publicly visible
You can directly assign lists to lists. Give it a try. In case it does not work, please attach some screenshots of your process node configurations.
I am trying something like this
a!forEach( items: ri!attachment, expression: reduce( a!update, fv!item, merge( {"attachmentDetailsId","folderId"}, {ri!attachmentDetailsId, ri!folderId} ) )
ri!attachmentDetailsId is an array
ri!attachment is attachment type array
Firstly I'd say that you don't need to reference the other table from BOTH tables. You really only need attachmentId in the Attachment Details table. Also, if it's a 1 to 1 relationship I'm not sure you need the extra table in the first place. This does depend on your exact use case but needing a description for an attachment doesn't feel like it needs an extra table (especially if a description is mandatory!). Also consider that a document in Appian can have a description too so you might not even need to save this in the database! Again...this does depend on the specific use case.
I'd suggest considering:
Hi, if there is one to one relationship I can't think of any use case where we need to maintain two tables. But in case you want this and there is some use case for the same. Below is one of the possible ways to do it
a!localVariables( /* Assuming this to be the initial state */ local!attachment: { { attachmentId: null, fileId: 123, attachmentDetailsId: null }, { attachmentId: null, fileId: 234, attachmentDetailsId: null } }, local!attachmentDetail: { { attachmentDetailsId: null, Description: "Evidence", attachmentId: null }, { attachmentDetailsId: null, Description: "Tracker", attachmentId: null } }, /* Wrtitng local!attachmentDetail to database using write to datastore entity will give back the Ids for the same */ local!attachmentDetailAfterWrite: { { attachmentDetailsId: 1, Description: "Evidence", attachmentId: null }, { attachmentDetailsId: 1, Description: "Tracker", attachmentId: null } }, /* We can use below to map the attachment detail in the attachment table */ local!attachmentBeforeWrite: a!forEach( items: local!attachment, expression: updatedictionary( fv!item, { attachmentDetailsId: property( index( local!attachmentDetailAfterWrite, fv!index, {} ), "attachmentDetailsId", {} ) } ) ) /* You can then write the attachment to database thus generating the Ids for the same and then use the similar way to map atatchment Ids to the attachment detail */ )
The output of the mapping forloop will be something like this
Hope it helps
Thanks Stefan Helzle for your reply.
Thanks ajhick for the answer. It was designed initially by senior tech leads that attachment table will be a common table for all the projects and attachmentDetails table is specific for my particular project where they want to store additional information for the attachments they are uploading. So unfortunatly I have to save the details as mentioned above.
Thanks viraty this worked for me.