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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Create Change Request from Problem Report and Default to same Container

zgodula
10-Marble

Create Change Request from Problem Report and Default to same Container

Hi,

I'm trying to auto-create the Change Request once the Problem Report has been confirmed (Accepted state).

I was able to do this with an Expression Robot from a PTC support site article using this code:

wt.change2.ChangeIssue ci =( wt.change2.ChangeIssue)primaryBusinessObject;

wt.change2.WTChangeRequest2 CRNew2 = wt.change2.WTChangeRequest2.newWTChangeRequest2();

CRNew2.setName(ci.getName());

CRNew2.setOrganization(ci.getOrganization());

wt.team.Team team = wt.team.TeamHelper.service.getTeam(ci);

if (team == null) {

team = wt.team.TeamHelper.service.getTeam(CRNew2);

}

CRNew2 = (wt.change2.WTChangeRequest2) wt.fc.PersistenceHelper.manager.save(CRNew2);

CRNew2 = (wt.change2.WTChangeRequest2) wt.fc.PersistenceHelper.manager.refresh(CRNew2);

//CRNew2.setCategory("Low");

System.out.println("IN ..Save...*********" + CRNew2.getNumber());

wt.change2.FormalizedBy fb = new wt.change2.FormalizedBy();

fb.setChangeIssue(ci);

fb.setChangeRequest2(CRNew2);

wt.fc.PersistenceServerHelper.manager.insert(fb);

This works to create the new ECR, but the problem is that it is created at the Site level, and not within whatever Context the Problem Report existed.

I know I'm missing something here.

Any idea what?

Thanks in advance,

Zack

ACCEPTED SOLUTION

Accepted Solutions
BineshKumar1
13-Aquamarine
(To:zgodula)

Add this to your code, this will the set the container of change request to change issues

CRNew2.setOrganization(ci.getOrganization());

CRNew2.setContainer(ci.getContainer());

On a side note, FormalizedBy link got replaced by ChangeProcessLink in WC 11

Thank you

Binesh Kumar

View solution in original post

4 REPLIES 4
BenLoosli
23-Emerald II
(To:zgodula)

Set the folder in the OIR, using context. Look in an existing OIR for Change Request and see who it is defined OOTB.

BineshKumar1
13-Aquamarine
(To:zgodula)

Add this to your code, this will the set the container of change request to change issues

CRNew2.setOrganization(ci.getOrganization());

CRNew2.setContainer(ci.getContainer());

On a side note, FormalizedBy link got replaced by ChangeProcessLink in WC 11

Thank you

Binesh Kumar

Thanks Binesh.

This worked and the ECR is now created in the same container as the Problem Report.

Now I just need to figure out why it's not assigning the Submit Change Request task to Change Admin 1.

Instead it's going to the Administrator.

Thanks again!

BineshKumar1
13-Aquamarine
(To:zgodula)

Hello Zack,

This is because the session is being run as administrator in the workflow. You can just flip it to issue creator, persist the object and then switch it back.

wt.change2.ChangeIssue ci =( wt.change2.ChangeIssue)primaryBusinessObject;

wt.org.WTUser prCreator = wt.org.WTUser.newWTUser(ci.getCreatorName()); 

System.out.println("************Creator of CI:" +prCreator.getName());

wt.org.WTPrincipal admin = wt.session.SessionHelper.manager.getPrincipal();

System.out.println("************Session User: " + admin.getName() );

wt.session.SessionHelper.manager.setPrincipal(prCreator.getName());

System.out.println("************Set the session user to:" + prCreator.getName());

wt.change2.WTChangeRequest2 CRNew2 = wt.change2.WTChangeRequest2.newWTChangeRequest2();

CRNew2.setName(ci.getName());

CRNew2.setOrganization(ci.getOrganization());

CRNew2.setContainer(ci.getContainer());

wt.team.Team team = wt.team.TeamHelper.service.getTeam(ci);

if (team == null) {

  team = wt.team.TeamHelper.service.getTeam(CRNew2);

}

CRNew2 = (wt.change2.WTChangeRequest2) wt.fc.PersistenceHelper.manager.save(CRNew2);

CRNew2 = (wt.change2.WTChangeRequest2) wt.fc.PersistenceHelper.manager.refresh(CRNew2);

//CRNew2.setCategory("Low");

System.out.println("IN ..Save...*********" + CRNew2.getNumber());

wt.change2.FormalizedBy fb = new wt.change2.FormalizedBy();

fb.setChangeIssue(ci);

fb.setChangeRequest2(CRNew2);

wt.fc.PersistenceServerHelper.manager.insert(fb);

wt.session.SessionHelper.manager.setPrincipal(admin.getName());

System.out.println("************Set the session user back  to:" + admin.getName());

Thank you,

Binesh Kumar

Announcements


Top Tags