Home > Forum > User Voice > [SOLVED] WEBCON: Update attachment action -> Q: How to rename attachments WITH continous numbering ?

[SOLVED] WEBCON: Update attachment action -> Q: How to rename attachments WITH continous numbering ?
0

MVP

Good morning everyone,

i am wondering, if someone of you already managed to rename the attachments with a kind of numbering within webcon.
Continous number or just the ATT_ID would be fine.

I am using one process for picture documentation and beside 6 picturefields there is the possibility to attach as many pictures as the user wants to the attachment section. After renaming them with the "update attachment action" while going to the next step, now all have the same name. It would be great if there is a way to give them unique filenames.

Thanks for your help,
Bjoern

MVP

Hi Bjoern,

I haven't tested this, but my best idea is to use a business rule for the attachment name.
The business rule would have two parameters, workflow id and attachment name. With this you should be able to identify the current attachment and return the new name with ATT_ID.

If this doesn't work for some reason, you could add a flow control step afterwards. A check is added, to verify that all attachments have an id in the name. Otherwise increase a counter (technical field), retrieve the first attachment without an Id, update it's name with the counter and test again. :)

An alternative would be to use an item list, whit linked attachments. Than the users could provide some more information and if the users only need an id to which they can refer, than the item list row id could be fine.

There's one draw back with the first option: If the user adds two attachments with the same name from different folders, this will probably fail. On the other hand, it may work, if the updates are processed sequential, than the first attachment is already renamed when the other ones name is determined.

Off topic:
Is there any chance to move this thread from 'user voice' to 'forum'.

Best regards,
Daniel

MVP
MVP
In reply to: Bjoern Poller

Hi Daniel,

thanks for your tricks to manage this problem. I will try them and post the results if something works.

Nevertheless i suggest a new function in the user voice for future WebCon versions.

Bye,
Bjoern

Good morning everyone,

I would like to share my solutions for this problem. Hopefully WebCon will implement a standard solution in future WebCon versions:

The solutuion shown in the picture is an "Action - Integration - Run a SQL procedure" for adding the ATT_ID....

MVP
In reply to: Bjoern Poller

And here the solution for continuous numbering......


Hope someone can use it. Thanks for all help.

Bye Bjoern

Hi Bjoern,

interesting idea but I would advise against this approach.

1. If you are lucky you are only in a "grey" area of violating the EULA:
-- 3.6. The Licensee may not make any Modifications itself.
-- 1.20 Modification – shall mean any change of the Software which results in a change of the
source code or interferes with the structures of the Environment Database by changing
the definitions of the tables, functions, procedures and database objects provided by
the Licensor or inserting or updating any records in the Environment Database in a
manner other than making use of the standard functionality of the Software or the
Software Development Tools (in particular by triggering the insert or update T-SQL
commands).

As far as I understand this, you could argue that you are only using standard functionality. If this would be a Microsoft product I'm sure you would your environment would not be supported any longer.

2. Have you checked the history? Are the changes tracked? Since there are no triggers on the table I don't think so.

If the above idea using the business rule doesn't work. The alternative would be to create a custom SDK action.
I haven't tested the below code in total, but it should work since I put this together from separate actions.

for(int i = 0; i < templateWorkflow.Attachments.Count; i++)
{
AttachmentData attachment = templateWorkflow.Attachments[i];
attachment.FileName = i.ToString()+"_"+attachment.FileName;
WebCon.WorkFlow.SDK.Documents.DocumentAttachmentsManager.UpdateAttachment(
new UpdateAttachmentParams()
{
Attachment = attachment,
SkipPermissionsCheck = true
});
}

Best regards,
Daniel

In reply to: Daniel Krüger (Cosmo Consult)

Hi Bjoern,

interesting idea but I would advise against this approach.

1. If you are lucky you are only in a "grey" area of violating the EULA:
-- 3.6. The Licensee may not make any Modifications itself.
-- 1.20 Modification – shall mean any change of the Software which results in a change of the
source code or interferes with the structures of the Environment Database by changing
the definitions of the tables, functions, procedures and database objects provided by
the Licensor or inserting or updating any records in the Environment Database in a
manner other than making use of the standard functionality of the Software or the
Software Development Tools (in particular by triggering the insert or update T-SQL
commands).

As far as I understand this, you could argue that you are only using standard functionality. If this would be a Microsoft product I'm sure you would your environment would not be supported any longer.

2. Have you checked the history? Are the changes tracked? Since there are no triggers on the table I don't think so.

If the above idea using the business rule doesn't work. The alternative would be to create a custom SDK action.
I haven't tested the below code in total, but it should work since I put this together from separate actions.

for(int i = 0; i < templateWorkflow.Attachments.Count; i++)
{
AttachmentData attachment = templateWorkflow.Attachments[i];
attachment.FileName = i.ToString()+"_"+attachment.FileName;
WebCon.WorkFlow.SDK.Documents.DocumentAttachmentsManager.UpdateAttachment(
new UpdateAttachmentParams()
{
Attachment = attachment,
SkipPermissionsCheck = true
});
}

Best regards,
Daniel

Is there a simple solution to do a substring on attachement name ?
The solution with business rule doesen't seem to work.
I get only {ATT_NAME} as a result for every attachement

select cast(substring(ATT_name, nullif(charindex('_',ATT_name),1)+1,LEN(ATT_name)) as nvarchar) from WFDataAttachmets where att_wfdid = {BRP:5} and Att_Name = N'{BRP:4}'

MVP
In reply to: jp

Is there a simple solution to do a substring on attachement name ?
The solution with business rule doesen't seem to work.
I get only {ATT_NAME} as a result for every attachement

select cast(substring(ATT_name, nullif(charindex('_',ATT_name),1)+1,LEN(ATT_name)) as nvarchar) from WFDataAttachmets where att_wfdid = {BRP:5} and Att_Name = N'{BRP:4}'

Hi jp,

you are right. The parameter {ATT_NAME} is still a placeholder when the business rule is executed, unfortunately. I verified this using the SQL profiler. I also noticed, that this is only executed once for all attachments. So this isn't an option anyway.

If you don't want to resort to a custom SDK action, you can do the following, to update the individual attachment names.
- Create a branch control which loops over the attachments. I added a field which is used as a counter.
- Update the next attachment in each loop


GetCurrentLoopAttachmentId sql command
select Att_ID
from (
select ATT_ID, ROW_NUMBER() OVER(ORDER BY ATT_ID ASC) AS RowNumber
from WFDataAttachmets
where ATT_WFDID = {WFD_ID}
) as temp
where RowNumber = LOOPCOUNTERFIELD

Remarks:
Depending on the number of attachments there could be a timeout problem.

I've tested this with 2021.1.3.205 adding the Att_ID to the name. Since this works, yours should work, too. If you are using the same version I can send you the .bpe package.


Best regards,
Daniel

In reply to: Martin Meze (Freelancer)

I just noticed that if you have more than 10 attachments that solution wouldn't work. I get the following error:
"Invalid configuration. The maximum number of consecutive transition paths that can be taken in one operation is 10."

Hello Martin. I´ve used the loop mechanism by storing my Item list to Share point, but I noticed the same limitation with maximal "10 consecutive transition paths..". Did you somehow solve the issue, or is this a technical limitation in Webcon which can not be solved?