Skip to main content
11-Garnet
April 1, 2016
Solved

Create Change Request from Problem Report and Default to same Container

  • April 1, 2016
  • 2 replies
  • 2898 views

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

Best answer by BineshKumar1

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

2 replies

23-Emerald III
April 1, 2016

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

1-Visitor
April 2, 2016

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

zgodula11-GarnetAuthor
11-Garnet
April 4, 2016

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!

1-Visitor
April 4, 2016

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