You are viewing limited content. For full access, please sign in.

Question

Question

Duplicate Workflow Shortcuts

asked on March 29, 2021

Here is our use case...

 

Customer selects 30 documents in the repository, edits the metadata and changes "approved" field to "yes".  This triggers a workflow instance on each document that performs some lookups, moving the document and creating a shortcut in a specific folder.

For ease of description, let's say I have 3 documents called York, Harrisburg and Lancaster.  All 3 have a "State" field set to "Pennsylvania" and a "Approved" field with blank or "yes" as options. 

There is a workflow with a starting rule of "Metadata changed" and "Approved field is not empty". 

In the workflow, we create a folder called "Pennsylvania" with a subfolder named as the County (ie York).  It then searches a "Shortcuts" folder for entries called "York".  If it finds it, it deletes it. In either case, it then creates a new shortcut to the "York" folder.

Here is the problem...

1. The Move (create shortcut) and Route Entry (Create Shortcut) activities will not overwrite an existing shortcut, it will duplicate it as "York(2)" for example.  This is why it has to search for existing shortcuts of the same name in the destination folder and delete them first.

2. If I select 20 entries and change the "Approved" to yes, it runs all 20 instances at the same time.  The problem is...

1. Instance 1 runs, finds there isn't a shortcut that already exists and will create one

2. Before Instance 1 can create the shortcut, Instance 2 runs, finds there isn't a shortcut that already exists (since instance 1 hasn't actually created it yet) and will create one.

3. Instance 1 then creates the shortcut "York"

4. Instance 2 tries to create the shortcut "York" since it didn't exist, but between the search and creation, however it now does exist so it creates "York (2)".

 

As a workaround, we created a separate workflow to invoke the processing and wait to invoke the next one until the current one is completed.  This works, but drastically increases how long it takes to process all 20 entries.

 

How can you overwrite a shortcut?

 

 

0 0

Replies

replied on March 29, 2021

I don't think there is a built-in way to overwrite when shortcuts.

What if you always created the shortcut, but then made a separate workflow that monitored for your Workflow user to create shortcuts in that folder, and when created, check if the name of the shortcut ends with the (2), (3), (4), etc. suffix at the end, and if it does, delete it?

0 0
replied on March 29, 2021

Another option that may work for you is the Delete Shortcuts activity. Rather than searching, run that to delete any existing shortcuts before creating a new one. This will remove all shortcuts everywhere, so if you have different logic to create shortcuts in different places you may need to recreate everywhere or use other logic.

0 0
replied on March 29, 2021

Or, search if the shortcut exists before creating it, and only create it if doesn't exist, and bypass the creation if it does.

0 0
replied on March 29, 2021

I already have a routine in there that checks if the shortcut exists.  If it does, I delete it and then create it.  Conversely, I also tried to check if if it exists and I only create if it doesn't.  In both cases the problem comes back to a race condition.  When one instance searches and doesn't find it, within the time it checks and the 1 second later that it creates it, another instance has already created one so it creates a duplicate.

I do like the thought of searching after completion and deleting any shortcuts that contain "(*)" at the end, but again the possibility of a race condition exists if I run the search and when I go to delete it at the end, it says it doesn't exist, however the previous workflow just hasn't completed processing yet.  We're talking about millisecond differences between create and delete/search activities between the running instances.  That's what has made this tough to nail down.

0 0
replied on March 29, 2021

That's why I was thinking to have it as a separate Workflow that is triggered from the actual creation of the shortcut by the Workflow user in the shortcuts folder.

If you have 5 workflows running, they'll create 5 shortcuts: York, York (2), York (3), York (4), York (5).  The creation of all 5 shortcuts trigger the second Workflow to process, but the first 1 will end without doing anything, and the other 4 will delete the shortcuts.

0 0
replied on March 29, 2021

Interesting thought...I will run this through some testing on our Sandbox server.

0 0
replied on March 29, 2021

I haven't done a test of it, so I could be off-base, but it at least seems to make sense logically.

0 0
replied on March 29, 2021

I have even tried bypassing the issue by using the workflow SDK to create the shortcut.  Using the Shortcut.Create method, it supports an EntryNameOption parameter that can be set to Overwrite.  Unfortunately, this does not work for shortcuts, as it just generates an error that the entry already exists.

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.