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

Workflow Customization - Java API Questions

TomU
23-Emerald III

Workflow Customization - Java API Questions

I am trying to customize the email notifications being sent from a workflow but I'm having trouble finding the right Java API calls to use for certain pieces of information.  Here are the calls I'm using so far:

wt.maturity.StandardMaturityService p = new wt.maturity.StandardMaturityService();
wt.maturity.PromotionNotice pn =(wt.maturity.PromotionNotice)primaryBusinessObject;
wt.fc.QueryResult pn_targets;
pn_targets = (wt.fc.QueryResult) p.getBaselineItems(pn);
wt.epm.EPMDocument epmDoc = new wt.epm.EPMDocument();
while (pn_targets.hasMoreElements())
{
     Object obj =pn_targets.nextElement();
     String objType =obj.getClass().getName();
     if (objType.equals("wt.epm.EPMDocument"))
     {
         epmDoc = (wt.epm.EPMDocument)obj;
         System.out.println("state = " + epmDoc.getState().toString());
         System.out.println("number = " + epmDoc.getNumber().toString());
         System.out.println("cadname = " + epmDoc.getCADName());
     }
}

These are working great, but I need more.  What are the calls to get the following:

  • Revision
  • Iteration
  • URL to object's detail page

I'm assuming there is some other method the EPM Document object has to be passed through, but I have no idea what it is.  I've done some looking through the Java Doc, but it is pretty overwhelming.  Any suggestions?

 

Thanks!

 

1 ACCEPTED SOLUTION

Accepted Solutions
olivierfresse
13-Aquamarine
(To:TomU)

 

Property page :

import wt.fc.ReferenceFactory

HashMap map = new HashMap(1);
ReferenceFactory referenceFactory = new ReferenceFactory();

map.put("oid", referenceFactory.getReferenceString(epmDoc));
String url =  urlFactory.getURL("app/#ptc1/tcomp/infoPage", map).toString();

Version & Iteration

// version
epmDoc.getVersionIdentifier().getValue()

// iteration
epmDoc.getIterationIdentifier().getValue()


 

Regards

View solution in original post

18 REPLIES 18
olivierfresse
13-Aquamarine
(To:TomU)

 

Property page :

import wt.fc.ReferenceFactory

HashMap map = new HashMap(1);
ReferenceFactory referenceFactory = new ReferenceFactory();

map.put("oid", referenceFactory.getReferenceString(epmDoc));
String url =  urlFactory.getURL("app/#ptc1/tcomp/infoPage", map).toString();

Version & Iteration

// version
epmDoc.getVersionIdentifier().getValue()

// iteration
epmDoc.getIterationIdentifier().getValue()


 

Regards

TomU
23-Emerald III
(To:olivierfresse)

Where are you finding these?  When I look at the EPMDocument class in the Java Doc, these methods aren't listed.  Should I be looking somewhere else?

olivierfresse
13-Aquamarine
(To:TomU)

 

Well the way PTC generates its JavaDoc is strange...

Many things are missing !

 


@TomU wrote:

Where are you finding these?  When I look at the EPMDocument class in the Java Doc, these methods aren't listed.  Should I be looking somewhere else?


Using an ide, such as Eclipse, will allow you to use auto completion on methods. You will discover many methods not documented or easily found in PTC's java docs. Of course many of these are not "supported" however I have been using "unsupported" methods for a long time. Always good to develop and test on a test server. You can build the code in an ide and then copy and paste over to the workflow expression editor.

 

I have also found many classes and methods from countless searches on this site and also PTC's site.

TomU
23-Emerald III
(To:olivierfresse)

Is "import" valid in a workflow expression?

Checking Syntax...
E:\ptc\Windchill_11.0\Windchill\temp\WfExpression395707948.java:36: error: illegal start of expression
import wt.fc.ReferenceFactory;
^
E:\ptc\Windchill_11.0\Windchill\temp\WfExpression395707948.java:36: error: not a statement
import wt.fc.ReferenceFactory;
            ^
2 errors
Syntax check complete.
olivierfresse
13-Aquamarine
(To:TomU)

Ah, no !!!

Workflow expressions end in java methods, so you must  use fully qualified name...

 

like

 

wt.fc.ReferenceFactory referenceFactory = new wt.fc.ReferenceFactory();
TomU
23-Emerald III
(To:olivierfresse)

urlFactory also had to be initialized.  Digging around on the community I found this line:

wt.httpgw.URLFactory urlFactory = new wt.httpgw.URLFactory();

It seems to be working perfectly!  Smiley Happy  I will post the final code block in a little bit.

 

For using these types of calls from a workflow expression, is it recommend to wrap everything in try/catch blocks, or are they fine as shown?  Thanks!

olivierfresse
13-Aquamarine
(To:TomU)

Good 🙂

It's a good thing to handle exceptions.

If you don't, the exception ends the workflow...

 

TomU
23-Emerald III
(To:olivierfresse)

@olivierfresse,

Do you know how I would retrieve the "friendly name" (localized value???) of the lifecycle states?  For example, instead of showing "INWORK" I would like to display "In Work".

epmDoc.getState().toString();


@TomU wrote:

@olivierfresse,

Do you know how I would retrieve the "friendly name" (localized value???) of the lifecycle states?  For example, instead of showing "INWORK" I would like to display "In Work".

epmDoc.getState().toString();

epmDoc.getLifeCycleState().getDisplay();

As it is a localized value, you can also pass the language

 

import wt.epm.EPMDocument
import wt.session.SessionHelper


epmDocument.getLifeCycleState.getLocalizedMessage(SessionHelper.getLocale())
TomU
23-Emerald III
(To:olivierfresse)

One more question.  I'm getting messages in the method server log about not escaping certain characters in the URL string.  Do I need to somehow escape these?  If so, how do I escape characters that are already encoded into an existing string?  (Some kind of search and replace???)  Will changing these mess up the URL?

 

<WT Home>/app/#ptc1/tcomp/infoPage?oid=VR%3Awt.epm.EPMDocument%3A393665313&u8=1"

Warning: unescaped & or unknown entity "&u8"

Thanks!

olivierfresse
13-Aquamarine
(To:TomU)

Hi,

As the URL is embedded in HTML code,I guess the & is seen as an HTML entity.

I don't know if PDMlink interprets the HTML tags... You may try to replace it by &amp; or %26

Anf if it doesn't work, I think you can simply ignore this warning 🙂

 

 

 

TomU
23-Emerald III
(To:TomU)

Thank you to everyone for the help.  I have accomplished my objective.  A table with the promotion objects (CAD Documents) has been constructed in a string variable and can be easily added to any task or notification robot email.

 

String:  promotion_objects

Usage: {promotion_objects}

Output:

table_final.PNG

Expression Code:

String style = "style=\"border: 1px solid; border-color:#808080; padding: 2px; padding-left: 6px; padding-right: 6px; font-weight: bold; color: white \"";
String style1 = "style=\"border: 1px solid; border-color:#808080; padding: 2px; padding-left: 6px; padding-right: 6px \"";
String style2 = "style=\"border: 1px solid; border-color:#808080; padding: 2px; padding-left: 6px; padding-right: 6px; background-color: #f7f7f7 \"";

promotion_objects = "<table style=\"font-size: 12px; color: #464646; border: 1px solid; border-color:#808080; font-family: arial; border-collapse: collapse\">\r\n";
promotion_objects =  (promotion_objects + "<thead style=\"background-color: #4caf50\"><tr>\r\n");
promotion_objects =  (promotion_objects + "<td " + style + ">Number</td><td " + style + ">Name</td><td " + style + ">Version</td><td " + style + ">State</td>\r\n");
promotion_objects =  (promotion_objects + "</tr></thead>\r\n");
promotion_objects = (promotion_objects + "<tbody>\r\n");

wt.fc.ReferenceFactory referenceFactory = new wt.fc.ReferenceFactory();
HashMap map = new HashMap(1);
wt.httpgw.URLFactory urlFactory = new wt.httpgw.URLFactory();

Integer i = 1;

wt.maturity.StandardMaturityService p = new wt.maturity.StandardMaturityService();
wt.maturity.PromotionNotice pn =(wt.maturity.PromotionNotice)primaryBusinessObject;
wt.fc.QueryResult pn_targets;
pn_targets = (wt.fc.QueryResult) p.getBaselineItems(pn);
wt.epm.EPMDocument epmDoc = new wt.epm.EPMDocument();
while (pn_targets.hasMoreElements())
{
    Object obj =pn_targets.nextElement();
    String objType =obj.getClass().getName();
    if (objType.equals("wt.epm.EPMDocument"))
    {
        epmDoc = (wt.epm.EPMDocument)obj;
        String epmNumber = epmDoc.getNumber().toString();
        String epmName = epmDoc.getName();
        String epmCADName = epmDoc.getCADName();
        String epmVersion = epmDoc.getVersionIdentifier().getValue();
        String epmIteration = epmDoc.getIterationIdentifier().getValue();
        // String epmState = epmDoc.getState().toString();
        String epmState = epmDoc.getLifeCycleState().getDisplay();

        map.put("oid", referenceFactory.getReferenceString(epmDoc));
        String epmURL =  urlFactory.getURL("app/#ptc1/tcomp/infoPage", map).toString();

        promotion_objects = (promotion_objects + "<tr>\r\n");
        if (i == 1) {
            promotion_objects = (promotion_objects + "<td " + style1 + ">" + epmNumber + "</td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style1 + "><a href=\"" + epmURL + "\">" + epmCADName + "</a></td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style1 + ">" + epmVersion + "." + epmIteration + "</td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style1 + ">" + epmState + "</td>\r\n");
            i = 2;
        } else {
            promotion_objects = (promotion_objects + "<td " + style2 + ">" + epmNumber + "</td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style2 + "><a href=\"" + epmURL + "\">" + epmCADName + "</a></td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style2 + ">" + epmVersion + "." + epmIteration + "</td>\r\n");
            promotion_objects = (promotion_objects + "<td " + style2 + ">" + epmState + "</td>\r\n");
            i = 1;
        }
        promotion_objects = (promotion_objects + "</tr>\r\n");
     }
}

promotion_objects = (promotion_objects + "</tbody>\r\n");
promotion_objects = (promotion_objects + "</table>");

System.out.println(promotion_objects);

Note: There is no error checking included.  (I'm really close to the 4000 character limit...)

Hi Folks...

 

I'm poking around the email notifications... the users here aren't impressed with the OOTB and seems like no one here is either.  I came across this post and was happy to see info like this.  I have nube questions though...

 

promotion_objects... how is it that every time that string variable is set... it doesn't over write the last...  it's writing the html text for each cell it looks like... how does it compile all that info using one string variable?

Dang it... always works like that... i ask the question and look at it again and go... ahh there it is... we are just adding to one loooooong string.

 

(is that right?)

TomU
23-Emerald III
(To:ChiselnMallet1)


@ChiselnMallet1 wrote:

... we are just adding to one loooooong string.

 

(is that right?)


Yes, that is correct.  All the extra HTML for the table is contained in that single string variable.  This makes it easy to insert anywhere it might be needed.

olivierfresse
13-Aquamarine
(To:TomU)

It's true that it's quite a big String 🙂

In fact, it would be more efficient to use a StringBuilder to create it

 

https://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html

 

 

Announcements