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

We are happy to announce the new Windchill Customization board! Learn more.

How to access promotion target comments from a workflow

TomU
23-Emerald IV

How to access promotion target comments from a workflow

Does anyone know the syntax required to access the comments entered for each promotion object line on a promotion request?

 

Promotion Request Comments.png

I have the syntax necessary to loop through each object in the baseline, but these are the actual EPMDocuments and don't contain the comments that are part of the promotion request (as far as I can tell.)

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();
...

What is the syntax necessary to get each row in the promotion request itself instead of just the objects on the baseline?

21 REPLIES 21
DmitryC
12-Amethyst
(To:TomU)

Hi Tom,

 

 Try using :

pn_targets = (wt.fc.QueryResult) p.getPromotionTargets(pn);

The full description is provided in JavaDocs in class StandardMaturityService and Interface MaturityService.

 

Dmitry.

TomU
23-Emerald IV
(To:DmitryC)

I still don't see how to retrieve comments from each of the promotion targets.  The pn_targets objects ('obj') are still just EPMDocuments (in my case).  It seems like the command should be something like "obj.GetComments", but for that to work 'obj' would need to refer to the "row" or "item" on the promotion request, not the actual EPMDoc.  As far as I can tell, the EPMDoc itself does not contain the promotion request comments.  What am I missing?

 

Test code:

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.getPromotionTargets(pn);
wt.epm.EPMDocument epmDoc = new wt.epm.EPMDocument();
while (pn_targets.hasMoreElements())
{
    Object obj =pn_targets.nextElement();
    String objType =obj.getClass().getName();
    System.out.println("Object Type: " + objType);
    if (objType.equals("wt.epm.EPMDocument"))
    {
        epmDoc = (wt.epm.EPMDocument)obj;
        String epmNumber = epmDoc.getNumber().toString();
        System.out.println("EPMDoc Number: " + epmNumber);
     }
}

Output:

[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03_SHCS.PRT
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03_4.PRT
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03.ASM
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03_3.PRT
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03_1.PRT
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03_2.PRT
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - Object Type: wt.epm.EPMDocument
[WfUserWorkQueue.PollingThread] wt.system.out Administrator - EPMDoc Number: T1370G03.DRW
jcrowe-2
4-Participant
(To:TomU)

This one is a bit tricky because the API doesn't spell it out clearly, but I have a solution for you.  You need to access the promotion targets instead of the epmdocument object.  The maturityhelper service will provide this when the (Promotion Notice, Boolean false) param is specified .  In this example, I get the Promotion comments for each of the promotion targets:

 

/*********************************************************
 * Get PromotionNotice
 * Query for PromotionTarget Links (this object accesses the promotion comments)
 * Get Promotion Comments from PromotionTarget
 ************************************************************/

/*Get PromotionNotice*/
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice)primaryBusinessObject;  
/*Query for PromotionTarget links (Promotion Notice, false)  setting this to false is the key*/
wt.fc.QueryResult promotionObjectLinks = wt.maturity.MaturityHelper.service.getPromotionTargets(pn, false);

 

while(promotionObjectLinks.hasMoreElements()){
  try{
   wt.maturity.PromotionTarget pt = (wt.maturity.PromotionTarget)promotionObjectLinks.nextElement();
   /*Get Promotion Comments and related EPMDocument object from PromotionTarget*/

   String promotionComments = pt.getDescription();  

    wt.epm.EPMDocument epmDoc = (wt.epm.EPMDocument)pt.getRoleBObject();

 

  //Do something with it...
   } catch(Exception wte) {
    wte.printStackTrace();      
    } 
  }

TomU
23-Emerald IV
(To:jcrowe-2)

Interesting.  So how do you correlate the comments with the CAD Docs?  Will the query result when the param is false contain the same number of entries as when the param is true?  Will they always be in the same order?

 

Ultimately I'd like to have the table I construct of promotion objects (CAD docs) include a column for these comments.  For that to work I need to correlate each comment with its corresponding CAD object.  Make sense?

jcrowe-2
4-Participant
(To:TomU)

Yep, makes sense. 

Q: How do you correlate the comments with the CAD Docs?

A: Get the comment, roleB object and add to some structure (Map, HashMap, etc.) perhaps.  Since number is unique in the system, you could correlate to that value.

String comment = pt.getDescription();

EPMDocument cadDoc = pt.getRoleBObject(); where pt is an instance of PromotionTarget

put in some structure(cadDoc.getNumber(), comment);

 

Q:  Will the query result always return the same number of entries?

A:  Yes

 

Q:  Will the query results always be in the same order?

A:   I assume so since it's reading the baseline, but regardless you can be certain that the comment will be associated to the corresponding CADDoc if you always get the roleB object.

 

 

JeffZemsky
17-Peridot
(To:TomU)

@TomU Have you thought about using the Promotion Objects table in your Workflow Layout?  It will show the Comments column.

 

1PRa.png

TomU
23-Emerald IV
(To:JeffZemsky)

@JeffZemsky,

I'm trying to get this information into the email messages.  See the table at the bottom of this picture:

 

Promotion Request Email.png

JeffZemsky
17-Peridot
(To:TomU)

Ah - yes so a little less direct.

 

Won't help you now but we are going to be working on some more customization and then configuration points for the notifications.

 

Let me noodle on this some.  Will you be at the PTC/USER sessions coming up?

TomU
23-Emerald IV
(To:JeffZemsky)


@JeffZemsky wrote:

Will you be at the PTC/USER sessions coming up?


Yes, I'm planning on being there.

Hello,

 

who knows, where promotion comments are stored in database?

 

My customer wants to increase the number of carracters.

 

Thanks and regards

Stefan

Hello, JeffZemskyplease tell me how you added Promotion Objects table in your Workflow Layout?
I tried to do that https://community.ptc.com/t5/Windchill/Where-to-write-the-code/td-p/630464 , but it didn't work.
That's what I did https://community.ptc.com/t5/Windchill/What-type-should-be-the-variable-obj/m-p/633206#M60480

@VladiSlav it is purely through configuration.

 

First you edit the Workflow Activity Templates -> Go to Templates and Task Form Templates.  There is an OOTB example in Review/Approve Promotion Request

 

 

2019-10-25_8-27-53.jpg

 

You can configure the Workflow Activity by creating Tabs and then populating the Tabs with Actions and Tables/Attributes all through the UI

 

2019-10-25_8-29-09.jpg

 

The final step is to set your workflow activity to use this template.  Note that once you do this any updates to your template are dynamic and show immediately in any running activity that uses the template.

 

2019-10-25_8-31-37.jpg

 

JeffZemsky, please specify, in the end it should turn out as You have in the screenshots? I opened the appropriate templates, but I have everything as you have

@VladiSlav Here are the two tabs you will see based upon that Task Template

 

2019-10-25_9-10-22.jpg

 

2019-10-25_9-10-30.jpg

 

JeffZemskymy page is different from yours. Or did I misunderstand you?
test.JPG

@VladiSlav What is on your Related Tab?

 

Also - my example is the OOTB workflow from 11.1 onwards. 

 

1.JPG2.JPG3.JPG4.JPG5.JPG6.JPG

JeffZemskyI have Windchill version 11.17.JPG

Did you configure your table view on your Promotion Objects to show the Comments column?

JeffZemsky, I didn't set up the table view, I wanted to add the "Promotion Objects" table to the "Task" page":

https://community.ptc.com/t5/Windchill/How-to-add-the-Promotion-Objects-table-to-the-Tasks-page/td-p/627590

Tell me, please, with the help of Your example it is possible to implement it?

 

3.jpg

 

d_graham
17-Peridot
(To:TomU)

In the dB the Comment is stored in the DESCRIPTION column in the PROMOTIONTARGET table. The PROMOTIONTTARGET table is a table that links the promotion object, in your case the EPMDocument, to the Promotion Request.
So, you can use the MaturityHelper.service.getPromotionTargets(“the promotion request”) to get a QueryResult of the targets then you can go thru the QueryResult to get both the promotion object and the corresponding comment. As you go thru the QueryResult you can add the promotion object and comment to a HashMap and when done return the HashMap.
Hope this helps.
Top Tags