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

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

API to check if any promotables are content type URLData?

austinrbaird
4-Participant

API to check if any promotables are content type URLData?

Version: Windchill 12.1

 

Use Case: In Promotion Request workflow, check if any of the promotables are WTDocuments with URLData as primary content. If yes, send a notification to a specific group


Description:

In a promotion request workflow, I'm trying to check if any of the promotables are WTDocuments with URLData as primary content and if so, send a notification to a certain group.  The only method I've found to possibly allow me to do this is getURLData, which returns a Vector.  Below is the code I've tried in a Conditional node in the workflow.  Testing by promoting a Document that's content is a URL, it returned result = NO

 

 

 

 

wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionSeeds(pn);
boolean isUrl = false;

while (queryResult.hasMoreElements()) {
	Object obj = queryResult.nextElement();
	if (obj instanceof wt.doc.WTDocument){
           	wt.doc.WTDocument doc = (wt.doc.WTDocument)obj;
		wt.content.ContentHolder ch = (wt.content.ContentHolder)wt.content.ContentHelper.service.getContents(doc);
		java.util.Vector urlData = wt.content.ContentHelper.getURLData(ch);
		if (!(urlData.isEmpty())) {
			isUrl = true;
		}
        }
}

if (isUrl==true) {
      result="YES";
}
else {
      result="NO";
}

 

 

 

 

 

As a different approach I also tried checking the value of the attribute 2 different ways, but with both of these the workflow doesn't seem to advance beyond the conditional node which houses the code

 

 

 

 

wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionSeeds(pn);
boolean isUrl = false;

while (queryResult.hasMoreElements()) {
	Object obj = queryResult.nextElement();
	if (obj instanceof wt.doc.WTDocument){
           	wt.doc.WTDocument doc = (wt.doc.WTDocument)obj;
		string formatName = doc.getFormatName();
		if (formatName == "URL Link") {
			isUrl = true;
		}
        }
}

if (isUrl) {
      result="YES";
}
else {
      result="NO";
}
wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionSeeds(pn);
boolean isUrl = false;

while (queryResult.hasMoreElements()) {
	Object obj = queryResult.nextElement();
	if (obj instanceof wt.doc.WTDocument){
           	wt.doc.WTDocument doc = (wt.doc.WTDocument)obj;
		PersistableAdapter pa = new PersistableAdapter(doc, null, java.util.Locale.US, new com.ptc.core.meta.common.DisplayOperationIdentifier());
		pa.load("formatName");
		java.lang.String fn = (java.lang.String) pa.get("formatName");
		if (fn=="URL Link") {
			isUrl = true;
		}
        }
}

if (isUrl==true) {
      result="YES";
}
else {
      result="NO";
}

 

 

 

 

Is this something that's possible or am I totally off the mark?  Anything wrong with my syntax/logic? Any help is appreciated.

p.s. I am not a developer/programmer

ACCEPTED SOLUTION

Accepted Solutions

One thing to start, I think you may want to use getPromotionTargets instead of getPromotionSeeds. Seeds are what the user initially selected to start the promotion request. More things may have been added since the initial selection. Targets will get you everything that is actually set for promotion.

 

I think you have an error here: 

string formatName = doc.getFormatName();
		if (formatName == "URL Link") {
			isUrl = true;
		}

 

Instead of:

if (formatName == "URL Link") {

 

Try:

if (formatName.equals("URL Link"){

 

Ref: https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

View solution in original post

3 REPLIES 3

One thing to start, I think you may want to use getPromotionTargets instead of getPromotionSeeds. Seeds are what the user initially selected to start the promotion request. More things may have been added since the initial selection. Targets will get you everything that is actually set for promotion.

 

I think you have an error here: 

string formatName = doc.getFormatName();
		if (formatName == "URL Link") {
			isUrl = true;
		}

 

Instead of:

if (formatName == "URL Link") {

 

Try:

if (formatName.equals("URL Link"){

 

Ref: https://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java

Thanks Joe, that was it. A simple error with a simple solution, thanks for being my 2nd set of eyes.  I also had to use the correct syntax java.lang.String instead of string, the compiler called that out easily enough

wt.maturity.PromotionNotice pn = (wt.maturity.PromotionNotice) primaryBusinessObject;
wt.fc.QueryResult queryResult = wt.maturity.MaturityHelper.service.getPromotionSeeds(pn);
boolean isUrl = false;

while (queryResult.hasMoreElements()) {
	Object obj = queryResult.nextElement();
	if (obj instanceof wt.doc.WTDocument){
           	wt.doc.WTDocument doc = (wt.doc.WTDocument)obj;
		java.lang.String formatName = doc.getFormatName();
		if (formatName.equals("URL Link")) {
			isUrl = true;
		}
        }
}

if (isUrl) {
      result="YES";
}
else {
      result="NO";
}

 

Oh, also noted about getPromotionTargets, that makes sense. I've updated that as well.  Thanks again!

Announcements

Top Tags