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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

How to Create a Baseline Programmatically

Toby.Pettit
12-Amethyst

How to Create a Baseline Programmatically

Hi,

I am looking to create a Managed Baseline programmatically.

We currently create an ECN programmatically, set it up using a few additional lines and persist it using the following:

cn = (WTChangeOrder2)ChangeHelper2.service.saveChangeOrder(cn);

Is there an equivalent for a Managed Baseline?

We are currently running 9.1 M060 but will be upgrading to 10.1 M0XX in a couple months. Whether it works in 9.1 does not matter.

Regards,

Toby

ACCEPTED SOLUTION

Accepted Solutions

Try this, you can also use code to set the folder, soft type etc.

ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();

myManagedBaseline.setName(name);

myManagedBaseline = (ManagedBaseline) PersistenceHelper.manager.save(myManagedBaseline);

BR

Simon

View solution in original post

8 REPLIES 8

Try this, you can also use code to set the folder, soft type etc.

ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();

myManagedBaseline.setName(name);

myManagedBaseline = (ManagedBaseline) PersistenceHelper.manager.save(myManagedBaseline);

BR

Simon

Spot on, thanks Simon.

I just tried this - didn't work. Could use some help.

I created a workflow template with just an expression robot with just this code, then initiated it from WF admin UI. How else can one test it?

Hi Mike,

Did you use fully qualified class names?

wt.vc.baseline.ManagedBaseline myManagedBaseline = wt.vc.baseline.ManagedBaseline.newManagedBaseline();

myManagedBaseline.setName(name);

myManagedBaseline = (wt.vc.baseline.ManagedBaseline)wt.fc.PersistenceHelper.manager.save(myManagedBaseline);

Something like that is what you need if you're using it in a workflow - use check syntax to make sure I have not missed one.

Also, the above code is looking for a variable called "name". If you want to hardcode it instead, just replace "name" in the "setName" method (line 3).

Regards,

Toby

That was it. Works perfectly now.

So - I created a WF variable and set the Name. Assume that to extend this to real usage I would present this variable to a user in a task to fill in the Name - true? Anything available to ensure that the name is unique? Maybe not so important because Number is already unique.

thanks very much

Yeah you create the variable in the assignment and make sure it is visible.

What I quite like to do in cases where there is only one piece of data the user is providing is to use the following in the relevent transition on the task to pick up what they enter in the "Comments" field:

wt.workflow.work.WfAssignedActivity act = (wt.workflow.work.WfAssignedActivity)self.getObject());

wt.workflow.engine.ProcessData data = act.getContext();

name = data.getTaskComments();

I personally wouldn't worry about the name uniqueness, I certainly won't be if we implement this. Someone else may be able to tell you how to if thats the route you want to go down.

Regards,

Toby

Toby,

Sorry I should have warned you, programming windchill is like pulling at a ball of tangled string, it quickly gets messy if you are not-experienced. Anyway I can give you a little help, I suggest testing code in a little main as follows. If you progress down this path further, think about externalizing and correctly managing code.

1. Put the attached file (below) here

src\net\wincomco\windchill\test

2. Compile it from a Windchill shell

javac -d %WT_HOME%\codebase -classpath %CLASSPATH%;%WT_HOME%\srclib\tool\Annotations.jar W:\ptc\Windchill\src\net\wincomco\windchill\test\CreateBaseline.java

3. Run it

windchill net.wincomco.windchill.test.CreateBaseline MyBaseline

4. It prints the oid of the new baseline e.g. wt.vc.baseline.ManagedBaseline:1094588729

5. Use the URL to find it (note your number will be different)

http://myhost/Windchill/app/#ptc1/tcomp/infoPage?oid=OR:wt.vc.baseline.ManagedBaseline:1094588729

6. It will be created in the Site > Folders, you need to start to learn how to create it where you want and populate it

You can transpose the code to workflows once you have it working

Simon

=====>

package net.wincomco.windchill.test;

import wt.vc.baseline.ManagedBaseline;

public class CreateBaseline {

public static void main(String[] args) throws Exception {
System.out.println("Start....");
String name = args[0];
ManagedBaseline myManagedBaseline = ManagedBaseline.newManagedBaseline();
myManagedBaseline.setName(name);
myManagedBaseline = (ManagedBaseline)wt.fc.PersistenceHelper.manager.save(myManagedBaseline);
System.out.println("===> myManagedBaseline " +myManagedBaseline);
}

}

Hi Simon,

I externalised our code around 2 years ago for several practical reasons. I would recommend that everyone does the same.

I tend to test all my code in a test instance workflow since it is easier and cannot do any real damage. The only nuiance I dont like is that once the code has been used it appears you have to stop the server and clear the cache if you want to make modifications.

Regards,

toby

Announcements


Top Tags