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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Translate the entire conversation x

Throw Warning Message in Custom Listener

marshall_brock
7-Bedrock

Throw Warning Message in Custom Listener

Version: Windchill 13.0


Description:

We have customized a PRE_WORKSPACE_CHECKIN listener to process an attachment file and populate attributes on the associated CAD document during the check-in process. It works great, but sometimes users forget to add the attachment, which results in none of the necessary attributes being populated. Is there a way to throw a warning (or error that can then be bypassed) to the user during check-in to tell them they are missing the attachment? Ideally I would like to call this in the custom listener.

 

public void notifyVetoableEvent(Object event) throws Exception{
	if(!(event instanceof KeyedEvent)) {
		return;
	}
	//Object target = ((KeyedEvent) event).getEventTarget();
	Object type = ((KeyedEvent) event).getEventType();
	if(type.equals(EPMWorkspaceManagerEvent.PRE_WORKSPACE_CHECKIN))
	{
		EPMWorkspaceManagerEvent wsEvent = (EPMWorkspaceManagerEvent) event;
		WTSet workingCopies = ((WTKeyedMap) ((EPMWorkspaceManagerEvent) event).getWIPMap()).wtKeySet();
		WTCollection epmDocs = workingCopies.subCollection(EPMDocument.class);
		Iterator docItr = epmDocs.persistableIterator(EPMDocument.class, true);
		while (docItr.hasNext()) {
			EPMDocument epmDoc = (EPMDocument) docItr.next();
			wt.fc.Persistable pers = (wt.fc.Persistable) epmDoc;
			com.ptc.core.meta.common.TypeIdentifier tiObj = wt.type.ClientTypedUtility.getTypeIdentifier(pers);
			String objType = tiObj.toString();
			if( objType.endsWith("VOCCADDocument")) {
				QCheckHelper qChecker = new QCheckHelper(epmDoc);
				
				// WARNING THROW SHOULD HAPPEN HERE, PSUEDO CODE INCLUDED FOR REFERENCE 
				if (qChecker.hasQCFile() == false) {
					new FeedBackMessage("Missing QC File! Continue check-in without adding?");
					// IF USER CLICKS "PROCEED" BELOW CODE EXECUTES AND POPULATES WITH BLANK VALUES
					// IF USER CLICKS "CANCEL" THE CHECK-IN IS ABORTED
				}
				// END OF PSUEDO CODE, REMAINING CODE WORKS AS EXPECTED
				
				Map<String, String> attr_value_map = new HashMap<String, String>(7);
				attr_value_map.put("QC_ACTACTION", qChecker.getActAction());
				attr_value_map.put("QC_ASSESSMENT", qChecker.getAssessment());
				attr_value_map.put("QC_CHECK_DATE", qChecker.getCheckDate());
				attr_value_map.put("QC_CHECK_TIME", qChecker.getCheckTime());
				attr_value_map.put("QC_CHECK_USER", qChecker.getCheckUser());
				attr_value_map.put("QC_PROFILE_NAME", qChecker.getProfileName());

				WTKeyedMap keyed_map = new WTKeyedHashMap(1);
				keyed_map.put(epmDoc, attr_value_map);

				EPMWorkspaceHelper.manager.setAttributes(wsEvent.getWorkspace() , keyed_map);
			}
		}
	}
}

 

6 REPLIES 6

Related to your other linked message, I did this on a rename listener by throwing a WTException

throw new WTException("Rename for Part " + master.getNumber() + " rejected since name length exceeds 40 characters for SAP");

though WTException is a hard no bypass way which might not work in your situation. 

 

Thanks for the response, but you are correct that this would produce a hard error with no bypass which is undesirable in my situation. This is what I plan to use as a last resort. I was hoping to find a solution using either the conflict manager (ConflictElement/Resolution API) or FeedbackMessage, but I'm not very familiar with either.

Hi @marshall_brock 

As I wrote, it it more complicated. 

here is an example how to create message with options for the error message

ArrayList<String> incorrectMessages = new ArrayList<>();
incorrectMessages.add("Delete WTP case ProcessPlan error!");

WTPDeleteMessage errorTitle = new WTPDeleteMessage("!!!! WARNING !!!!: ", "35", new Object[]{incorrectMessages});

ConflictType cType = WTPDeleteConflictType.DELETE_WTP_NOT_ALLOWED;
ResolutionType rType = ResolutionType.RETRY;
ResolutionType sType = ResolutionType.SKIP;
ConflictElement conflictElement = new ConflictElement(cType, new ResolutionType[]{sType, rType}, sType, errorTitle, wtp);
ConflictException conflict = new ConflictException(new ConflictElement[]{conflictElement});

ResolutionType resolutionList = ConflictServerHelper.getResolution(wtp, cType); // VERY IMPORTANT API TO GET RESOLUTION OPTIONS

if (resolutionList == null)
{
	throw conflict;
} else
{
	String option = resolutionList.getDisplay(Locale.US);

	if (option.equals("Retry"))
	{
		logger.info(String.format("WTPart linked to Process Plan is deleted. WTPart: %s, Process Plan: %s User %s", wtp.getNumber(), plan.getNumber(), user.getName()));
	} else
	{
		throw conflict;
	}
}

 

API to override conflict on EPMWorkspaceHelper.manager.checkout

You have to create own conflict type 

In my example I used own class WTPDeleteConflictType

How to create RbInfo file

How to create a drop down list in a workflow instance task detail page of Windchill PDMLink

 

Also I created own WTPDeleteMessage based on WTMessage.class

 

Hope this can help you.

 

PetrH

Thank you for the response with an example! I will give this a try. 

Hello @marshall_brock,

 

It looks like you have some responses from some community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Vivek N.
Community Moderation Team.

I think we can use FormProcessingStatus.NON_FATAL_ERROR. This gives warning and proceeds with rest of the tasks.

 

Previously I had the same requirement and achieved the result with this.

Announcements
Top Tags