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

Question

Question

Skip document if locked (try-catch expected error handling)

asked on December 12, 2019 Show version history

I have a workflow that runs a search, then iterates through each document in the search. There is an Assign Field Values action in the loop. In the case of a document that's checked out, it will try to assign the metadata, but since it's checked out, it will throw the "Document locked with a persistent lock" error, which has built-in error handling in Workflow Admin Console to retry every 6 hours.

As a result, it gets to that document, retries 50 times, then terminates the workflow almost 2 weeks after it started. This workflow runs daily and every instance is terminating 2 weeks later because of that one checked-out document.

It is important that this workflow finishes the day it started.

I tried putting in a try-catch block to catch the "persistent lock" action, but apparently an expected error that retries every so often does not count as an error, only a warning, so the block does not catch it.

I can change the error retry time to 1 minute or remove the retry completely, but the workflow is currently waiting the 6 hours and I assume that change will not be reflected until the 6 hours are up.

Is there a way I can handle this situation, ideally without messing with the 6 hour retry time?

A) Want to get the "stuck" instance for today to continue past the checked out document to the rest of the documents before the day is over.

B) Want to prevent this issue from happening in the future if a document is checked out.

 

Thank you

 

EDIT: I believe I have found a workaround for this

 

 

try
            {
                DocumentInfo di = (DocumentInfo)this.BoundEntryInfo;
                FieldValueCollection fvc = di.GetFieldValues();
                //fvc.Add("Account Name","ddd");
                fvc["Account Name"]="dadfdfdd";
                di.Lock(LockType.Exclusive);
                di.SetFieldValues(fvc);
                di.Save();
                di.Unlock();
            }
            catch(Exception ex)
            {
                if(ex.Message.Equals("Document locked with a persistent lock. [9167]")){
                    throw new Exception("Cannot assign metadata because document is checked out.");
                }
                else
                {
                    throw new Exception("Unable to assign metadata.");
                }
            }

 

0 0

Answer

SELECTED ANSWER
replied on December 16, 2019

I was going to say something similar. Wouldn't it be easier if you just excluded checked out documents from the search that feeds For Each Entry?

2 0

Replies

replied on December 16, 2019

Rather than have your SDK attempt to update the entry and error out, use an if statement to check that the entry is not locked {!(di.IsLocked) and/or !(di.IsPersistentlyLocked)} and only run the update code if the entry is not locked.

1 0
SELECTED ANSWER
replied on December 16, 2019

I was going to say something similar. Wouldn't it be easier if you just excluded checked out documents from the search that feeds For Each Entry?

2 0
replied on December 13, 2019 Show version history

Did you always have a Try-Catch block inside of your script? Something worth noting is that if the exception is handled within the code, it will never make it up to the try-catch workflow activity.

Typically (depending on the process) I will just use a Try-Finally (I use the finally to set output tokens to ensure they always exist) with no Catch in the code, then I let a Workflow Try-Catch handle the exception.

Another thing to check is the settings for Scripting Options. By default, unhandled exceptions in a WF script report Warnings and not Errors (WF Admin Console > Security > Scripting > Properties).

Warnings may not trigger an error that can be caught by the Try-Catch event. If you change that to flag unhandled exceptions as Errors, it would allow the Try-Catch to detect the event properly.

However, it is worth noting that changing this setting could have undesired consequences because that would inevitably effect any other workflow scripts with unhandled exceptions.

0 0
replied on December 16, 2019

If the exception is caught within the code, it will make it up to the try-catch workflow activity if you throw a new exception within the catch block. Also, you can click the gear icon on the individual Script/SDK Script activity to report unhandled exceptions as an error rather than changing that server-wide.

 

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

Sign in to reply to this post.