Skip to main content
15-Moonstone
April 15, 2021
Solved

Windchill API to check if a certain version of object is published or not and then publish

  • April 15, 2021
  • 2 replies
  • 4723 views

Hi All,

 

can we know if there is any code or API to know certain version of object is published or not ? Or can we know if there is an API to know if the object is published or not so that we can then publish it ?

Best answer by BenPerry

@aachanta

Just wanted to clarify if you're talking about creating visualizations, or publishing using ESI.

 

Assuming you mean visualizations - yes, there is some API.  I have a method I created a while ago that runs in a workflow expression robot.  It calls the custom package/method.

 

The method returns true/false.  If it returns false, the method submits a publish job and the workflow routes to a timer robot.  If it returns true, then it continues.  There is also a custom logger in the example.  It isn't necessary.

 

 public static boolean representationCheck (WTChangeOrder2 co, boolean publish, int count) throws WTException {
 //checks to see if all of the Resulting objects are published. if they aren't published, it will submit publish jobs for them.
 boolean result = true;
 
 LOGGER.debug("WF Util: representationCheck: Calling ext.site.WorkflowUtils.representationCheck(), time #" + count + ", ECO# " + co.getNumber() + ", with publish mode = " + publish);
 try{
 // Get a list of the Resulting Objects of the Change Notice
 QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(co);
 
 // Loop through the Resulting Objects.
 while (qr.hasMoreElements()) {
 WTObject obj = (WTObject)qr.nextElement();
 
 // If the WTObject is an EPMDocument, check to see if it has a representation.
 if (obj instanceof EPMDocument) {
 EPMDocument epmDoc = (EPMDocument)obj;
 Representation rep = PublishUtils.getRepresentation((Representable) epmDoc);
 LOGGER.debug(" \"" + epmDoc.getIdentity() + "\" representation: " + rep);
 
 // If there is no representation for the EPMDocument, then submit a publish job for one.
 if (rep == null) {
 result = false;
 if (publish) {
 String objRef = ObjectReference.newObjectReference(epmDoc).toString();
 Publisher pub = new Publisher();
 PublisherAction publisherAction = new PublisherAction();
 publisherAction.addAction(PublisherAction.QUEUEPRIORITY, "H");
 result = pub.doPublish(false, true, objRef, (EPMAsStoredConfigSpec)null, (EPMAsStoredConfigSpec)null, true, null, null, Publisher.EPM, publisherAction.toString(), 0);
 LOGGER.debug("WF Util: representationCheck: Publish Job submitted for \"" + epmDoc.getIdentity() + "\"");
 }
 }
 }
 }
 LOGGER.debug("WF Util: representationCheck: Done with ext.site.WorkflowUtils.representationCheck(). All Resulting EPMDocs published? " + result);
 return result;
 }catch (Exception e) {
 e.printStackTrace();
 LOGGER.error("WF Util: representationCheck error checking representations, please see MS logs for stack trace");
 return true;
 }
 }

 

2 replies

BenPerry15-MoonstoneAnswer
15-Moonstone
April 15, 2021

@aachanta

Just wanted to clarify if you're talking about creating visualizations, or publishing using ESI.

 

Assuming you mean visualizations - yes, there is some API.  I have a method I created a while ago that runs in a workflow expression robot.  It calls the custom package/method.

 

The method returns true/false.  If it returns false, the method submits a publish job and the workflow routes to a timer robot.  If it returns true, then it continues.  There is also a custom logger in the example.  It isn't necessary.

 

 public static boolean representationCheck (WTChangeOrder2 co, boolean publish, int count) throws WTException {
 //checks to see if all of the Resulting objects are published. if they aren't published, it will submit publish jobs for them.
 boolean result = true;
 
 LOGGER.debug("WF Util: representationCheck: Calling ext.site.WorkflowUtils.representationCheck(), time #" + count + ", ECO# " + co.getNumber() + ", with publish mode = " + publish);
 try{
 // Get a list of the Resulting Objects of the Change Notice
 QueryResult qr = wt.change2.ChangeHelper2.service.getChangeablesAfter(co);
 
 // Loop through the Resulting Objects.
 while (qr.hasMoreElements()) {
 WTObject obj = (WTObject)qr.nextElement();
 
 // If the WTObject is an EPMDocument, check to see if it has a representation.
 if (obj instanceof EPMDocument) {
 EPMDocument epmDoc = (EPMDocument)obj;
 Representation rep = PublishUtils.getRepresentation((Representable) epmDoc);
 LOGGER.debug(" \"" + epmDoc.getIdentity() + "\" representation: " + rep);
 
 // If there is no representation for the EPMDocument, then submit a publish job for one.
 if (rep == null) {
 result = false;
 if (publish) {
 String objRef = ObjectReference.newObjectReference(epmDoc).toString();
 Publisher pub = new Publisher();
 PublisherAction publisherAction = new PublisherAction();
 publisherAction.addAction(PublisherAction.QUEUEPRIORITY, "H");
 result = pub.doPublish(false, true, objRef, (EPMAsStoredConfigSpec)null, (EPMAsStoredConfigSpec)null, true, null, null, Publisher.EPM, publisherAction.toString(), 0);
 LOGGER.debug("WF Util: representationCheck: Publish Job submitted for \"" + epmDoc.getIdentity() + "\"");
 }
 }
 }
 }
 LOGGER.debug("WF Util: representationCheck: Done with ext.site.WorkflowUtils.representationCheck(). All Resulting EPMDocs published? " + result);
 return result;
 }catch (Exception e) {
 e.printStackTrace();
 LOGGER.error("WF Util: representationCheck error checking representations, please see MS logs for stack trace");
 return true;
 }
 }

 

aachanta15-MoonstoneAuthor
15-Moonstone
April 21, 2021

Hi Ben

 

@BenPerry 

 

Thanks for the input. This helps a lot. But then can you please confirm what if the publishing fails ?

 

Will it get republished again ? If yes is there any count or limit on sending to publishing again

15-Moonstone
April 21, 2021

The method returns a boolean.  So you can call the method in an Execute Expression robot or Conditional in the workflow.  Based on the result, you can route to a 5-min timer (if the result was false) or continue forward (if the result was true).

18-Opal
April 21, 2021

Not sure if this got resolved but the way I handled this is to run code that gets the QueueEntry of the publishing job.

From there, every 30 seconds (can be whatever but 30 seconds seems to work well) I get the status.  If status is COMPLETED, NONEVENTFAILED or SEVERE I know the entry has finished.

Once finished I get the publishing job status. If it JOB SUCCESSFUL all is good. If it's not there's a problem and from there you can do whatever you want. Republish, send notification to user, whatever.

 

This seems to be a bombproof way of determining if the Representable was published successfully.

 

David

 

David

4-Participant
December 11, 2024

Can you please send the code you implemented ?