Skip to main content
3-Newcomer
July 18, 2024
Solved

Help on Query spec for subfolder

  • July 18, 2024
  • 1 reply
  • 841 views

Version: Windchill 11.2

 

Use Case: I would like to perform windchill query spec for the following statement

SELECT NAME FROM SUBFOLDER WHERE ida3containerreference=80556;

 

below is my code:

public class qeurytest { public static void showFolder() throws WTException {

 

QuerySpec qs=new QuerySpec();

 qs.setAdvancedQueryEnabled(true);

 

 int foldertable=qs.appendClassList(wt.folder.SubFolder.class, false); ClassAttribute ca1 = new

ClassAttribute(SubFolder.class,SubFolder.NAME);

 

qs.appendSelect(ca1, new int[] {foldertable}, true);

 

SearchCondition sc= new SearchCondition(SubFolder.class,SubFolder.CONTAINER_ID,SearchCondition.EQUAL,"80556");

 

qs.appendWhere(sc,new int[] {foldertable}); 

 

System.out.println("Printing the queryspec of class --> " + qs); }


Description:

I am facing an error : Attribute "containerReference.key.id" of class "java.lang.Long" is not of type "java.lang.String"

why is this error coming up and what would be the windchill queryspec for the statement.

 

Thank you 

Best answer by HelesicPetr

Hi @ED_11031300 

It is common mistake in your definition

Do not use the String definition because the ID is in Long type.

So use there the number 80556 without "

new SearchCondition(SubFolder.class,SubFolder.CONTAINER_ID,SearchCondition.EQUAL,80556);

PetrH

1 reply

HelesicPetr
22-Sapphire II
22-Sapphire II
July 25, 2024

Hi @ED_11031300 

It is common mistake in your definition

Do not use the String definition because the ID is in Long type.

So use there the number 80556 without "

new SearchCondition(SubFolder.class,SubFolder.CONTAINER_ID,SearchCondition.EQUAL,80556);

PetrH

3-Newcomer
July 25, 2024

Hello @HelesicPetr 

Thank you for replying I thought SubFolder.CONTAINER_ID was having the issue thanks for clarifying, However 80556 is integer I had to type cast it to long.

 

new SearchCondition(SubFolder.class,SubFolder.CONTAINER_ID,SearchCondition.EQUAL,(long)80556);

 

Thanks again!