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 do I add new values using QuerySpec?

VladiSlav
17-Peridot

How do I add new values using QuerySpec?

Hi, everybody.I found an example ( BineshKumar1  https://community.ptc.com/t5/Windchill/Updating-user-details-in-Windchill/m-p/267772 ) of how to update a value in a table in a database.
But I can't figure out how I can add new values ( a new row in the table) in this way .
Please tell me how this can be done?

 

Here is an example from the link https://community.ptc.com/t5/Windchill/Updating-user-details-in-Windchill/m-p/267772

 

 

try {
     QuerySpec qs = new QuerySpec(WTUser.class);
     qs.appendWhere(new SearchCondition(WTUser.class, WTUser.EMAIL, 
         SearchCondition.LIKE, "oldemail@oldemail.com", true), null);
     QueryResult qr = PersistenceHelper.manager.find((StatementSpec) qs);

     while (qr.hasMoreElements()) {
         WTUser user = (WTUser)qr.nextElement();
         user.setEMail("someone@something.com");
         PersistenceHelper.manager.save(user);
     }
} catch (WTException | WTPropertyVetoException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();  
}

 

 

 

5 REPLIES 5

Hi 

Could you please try for custom object first to generate the attributes/row via annotation i.e @GenAsPersistable and generate the table using below command

 

ant -f bin/tools.xml sql_script -Dgen.input= Package Name or class name

 

This command is used to generate the SQL script in the <WC HOME>/db directory. Please refer to the article CS259484 for more details.

 

Execute the table script that is located in /DB folder and you will have the won table of your object.

 

Or You can create the custom attributes via types and manager and Set the value by programmatically.

 

Thanks,
Shriram.

 

 

 

DmitryC
12-Amethyst
(To:VladiSlav)

Hi 

 

 

Can you elaborate on 'Adding a new row' part?

 

In any case, every row (or a combination of rows) represents an object in Windchill, so you should use proper API methods if you want to create something new.

 

The standard approach would be to:

1. Create an object in java session using its constructor or a static factory method

2. Set all the required attributes

3. Persist the object

4. Add whichever additional information you may require

5. Persist the changes

 

Here is an example java docs for WTParts: <WindchillHostName>/Windchill/wt/clients/library/api/wt/part/WTPart.html 

Also sometimes I use this GitHub project with different Windchill utils as a good reference: https://github.com/windchill-api/-/blob/master/elead/src/cn/elead/tool/wc/PartUtil.java

 

 

Kind regards,

Dmitry.

VladiSlav
17-Peridot
(To:DmitryC)

shrdeshmukh, DmitryC, thank you very much for the information.
I ran the example with Pet from the documentation, SQL queries were generated. Everything works as shown in the screenshots.
Now I will try to implement your answers by adding a new entry to the table.

 

There was also a question unrelated to the topic: "How do I change the display of table column names? I use Cyrillic ( Russian names). For example, "Name" is already displayed as a "Обозначение", but this has already been done before me, I do not understand how to do this with other columns.

DmitryC
12-Amethyst
(To:VladiSlav)

Hi VladiSlav,

 

 


@VladiSlav wrote:

How do I change the display of table column names?


Have you tried changing the localization in Type and Attribute Management?

That's what is driving the names of most of the columns:

Locale.PNG

 

Kind regards,

Dmitry.

1)Can you try via Resources bundle label or RBInfo file

2)For Table Builder - You can try like this.

//get the ComponentConfigFactory
ComponentConfigFactory factory = getComponentConfigFactory();
//get an instance of TableConfig
TableConfig table = factory.newTableConfig();

table.addComponent(factory.newColumnConfig("Columns Name",true));

3)Change the localization in Type and Attribute Management.

 

Thanks,

Shriram.

 

Top Tags