cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

A workflow is getting terminated when the object is in checked out state. How to avoid workflow termination

pvr
1-Visitor
1-Visitor

A workflow is getting terminated when the object is in checked out state. How to avoid workflow termination

Workflow gets terminated when the user clicks on complete task while keeping the object is in checked out state. How to avoid the workflow termination? Would like to give a warning message to the user that object is in checked out state and previous activity should work. Please let me know how to do this.

Thanks in advance

ACCEPTED SOLUTION

Accepted Solutions
tgudobba
14-Alexandrite
(To:pvr)

Prasi,

Add this to the condition in the required transition under the Transition tab of the workflow activity;

if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) primaryBusinessObject))

{

throw new java.lang.Exception("The workflow document is checked out, Please check it in to complete this task!");

}

View solution in original post

8 REPLIES 8
tgudobba
14-Alexandrite
(To:pvr)

Prasi,

Add this to the condition in the required transition under the Transition tab of the workflow activity;

if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) primaryBusinessObject))

{

throw new java.lang.Exception("The workflow document is checked out, Please check it in to complete this task!");

}

MikeLockwood
22-Sapphire I
(To:tgudobba)

This is great if it will work - much simpler than Business Rules.  Must be doing something wrong - just tried in multiple locations in a promotion - throws queue error.

Would this be added in an expression robot or the Start transition of an approval activity, or in the first conditional (which already has branching code) in the OTB promotion approval workflow template or other?

Are there some import statements or additional code needed in front of it?

pvr
1-Visitor
1-Visitor
(To:tgudobba)

hai..

I have included this code in the complete transition of each activity and it throws error when the object is in checked out state and not permitting the user to complete the task. After that the user can do undo check out or check in and then complete task. Workflow is not getting terminated.

Thank you very much.

MikeLockwood
22-Sapphire I
(To:pvr)

I'd like to find a way to put this near the beginning of a process before any tasks - to catch checked out items on a promotion request.

Where would you suggest putting the code (and does the code need to be modified) in order to do this?

thank you

To be able to do this, and not get the workflow abort, you'll need to do the following:

  1. Create an "OR" condition with the code to check if the object is checked out or not. There will be 2 transitions out of the "OR" condition
    1. One transition is for success condition, which means that no object is checked out, so the transition will go forward normally to the regular workflow.
    2. Another transition is for failure condition, which means that the object is checked out, connect the transition to an assigned activity to the role that should go back and check-in the object.

This works well for the primary object. Is there a way to adjust the script so that it would also check the 'descendants' of the primary object? For instance, we are starting workflows on maps which have several maprefs (english doc, french doc & metadata doc). At any given time one of the maprefs could be checked out, but not the map (primary object). Is it possible to have the script stop the workflow task if one of the maprefs is checked out?

Is there any way to include descendants with primaryBusinessObjects? if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) primaryBusinessObject)) { throw new java.lang.Exception("The workflow document is checked out, Please check it in to complete this task!"); }

Actually I don't think anyone would check-out a primaryBusinessObject. In the case of the Change Workflow, the primaryBusinessObject is either the Change Request or the Change Notice or the Change Task object. So, the isCheckedOut method should not be used in the first place.

However, the primaryBusinessObject (i.e., either the Change Request or Change Notice or the Change Task) could have multiple Affected Objects/Resulting Objects that you can navigate to and check for each of them if anyone is checked out.

The Windchill API has service class methods to get all the affected or resulting items for either a Change Activity or for the affected or resulting items for all the Change Activities for a Change Notice or the affected objects for a Change Request.

So, within the workflow for a Change Object i.e., the primaryBusinessObject is the Change Object itself.

  1. Within the Change Request workflow, the primaryBusinessObject is the Change Request
  2. Within Change Notice workflow, the primaryBusinessObject is the Change Notice
  3. Within the Change Activity workflow, the primaryBusinessObject is the Change Activity

Lets say for example, we are within a Change Activity workflow, and we want the list of all the Affected Objects. Then, within the expression robot (or the OR condition), you would add the code to get a list of all the Affected Objects and then check each of them whether they are checked-out or not. Here's the sample code:

//Comments: Get the list of all the affected objects for the current Change Activity

wt.fc.QueryResult affectedObjectsQR = wt.change2.ChangeHelper2.service.getChangeablesBefore((wt.change2.ChangeActivityIfc) primaryBusinessObject, true);

//Comments: Loop through each affected object and find if its checked out or not ?

while (affectedObjectsQR.hasMoreElements()) {

     wt.vc.wip.Workable affectedObject = (wt.vc.wip.Workable) affectedObjectsQR.nextElement();

     if(wt.vc.wip.WorkInProgressHelper.isCheckedOut(affectedObject)) {

          //Comments: if the affected object is checked out, then take appropriate action - like route it to someone who can fix the problem

          result = "FixCheckouts";

          break;

          //If you have set a routing option in the OR condition called "FixCheckouts", then the flow will navigate through that route.

     }

}

Similar API is available for Change Request and Change Notice also.

The affected objects that you get from the QueryResult could be Parts, Document etc.

If you want to check if the affected object is Part or a Document, then you can do additional checks as follows:

if (affectedObject instanceof wt.part.WTPart) {

     // Do something useful with the part

}

if (affectedObject instanceof wt.doc.WTDocument) {

     // Do something useful with the document

}

You can use additional API's to navigate from the Part to its associated documents or from a Document to its associated documents also. Lets take for example we want to check all the references or referenced by documents from the current document. See the code below:

If you want to check if all the References Documents from the current Document are checked out, then see below:

if (affectedObject instanceof wt.doc.WTDocument) {

     //We are casting the affected object to the WTDocument

     wt.doc.WTDocument currentDocument = (wt.doc.WTDocument) affectedObject;

     // Here you try to get the References Documents

     wt.fc.QueryResult referencesDocumentQR = wt.doc.WTDocumentHelper.service.getDependsOnWTDocuments(currentDocument, true);

     //Loop through all the References Documents

     while (referencesDocumentsQR.hasMoreElements()) {

          wt.doc.WTDocument referencesDoc = (wt.doc.WTDocument) referencesDocumentsQR.nextElement();

          //Check if the document is checked out

          if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) referencesDoc)) {

               //Do something like route it to some other activity so that a user can get a task to do something about it

               result = "FixCheckouts";

               break;

          }

     }

}

If you want to check if all the ReferencedBy Documents from the current Document are checked out, then see below:

if (affectedObject instanceof wt.doc.WTDocument) {

     //We are casting the affected object to the WTDocument

     wt.doc.WTDocument currentDocument = (wt.doc.WTDocument) affectedObject;

     // Here you try to get the ReferencedBy Documents

     wt.fc.QueryResult referencedByDocumentsQR = wt.doc.WTDocumentHelper.service.getHasDependentWTDocuments(currentDocument, true);

     //Loop through all the Referenced By Documents

     while (referencedByDocumentsQR.hasMoreElements()) {

          wt.doc.WTDocument referencedByDoc = (wt.doc.WTDocument) referencedByDocumentsQR.nextElement();

          //Check if the document is checked out

          if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) referencedByDoc)) {

               //Do something like route it to some other activity so that a user can get a task to do something about it

               result = "FixCheckouts";

               break;

          }

     }

}

Note: I have not checked for the syntactical correctness of the code as I've just typed here but didn't validate the code against an IDE. So, please check if the code syntax is right and the package extensions are provided correctly to all the classes in the code. If not, the workflow editor will complain with errors.

Announcements


Top Tags