HI,
Need to reassign some documents for a specific state.
I am using this java code, but I have difficulty to set the state that the life cycle should start.
package com.anderson.testes;
import wt.doc.WTDocument;
import wt.fc.WTObject;
import wt.lifecycle.LifeCycleHelper;
import wt.lifecycle.LifeCycleManaged;
import wt.lifecycle.LifeCycleState;
import wt.lifecycle.LifeCycleTemplateReference;
import wt.org.WTPrincipal;
import wt.session.SessionHelper;
import wt.util.WTException;
public class WfTest {
public static void main(String[] args) {
wt.doc.WTDocument user = null;
String number = "OEP001-00-OEP-0000-DE-C121-0019";
try{
String obid = "VR:wt.doc.WTDocument:478422008:542998064-1353037556831-1605728400-85-120-154-10@oepsp039wi.odebrecht.net";
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
String[] array = org.apache.commons.lang.StringUtils.split(obid, ':');
wt.fc.WTReference ref = rf.getReference(array[0] + ":" + array[1] + ":" + array[2]);
System.out.println("Obj: "+ref.getObject());
user = (wt.doc.WTDocument) ref.getObject();
WTPrincipal getUser = SessionHelper.manager.getPrincipal();
wt.query.QuerySpec qs = new wt.query.QuerySpec(wt.doc.WTDocument.class);
qs.setAdvancedQueryEnabled(true);
// qs.appendWhere(new wt.query.SearchCondition(wt.doc.WTDocument.class, "master>number" , wt.query.SearchCondition.LIKE,number), new int[] { 0 });
qs.appendWhere(new wt.query.SearchCondition(WTDocument.class, WTDocument.BRANCH_IDENTIFIER, wt.query.SearchCondition.EQUAL, new Long(user.getBranchIdentifier())));
qs.appendAnd();
qs.appendWhere(new wt.query.SearchCondition(wt.doc.WTDocument.class, "iterationInfo.latest" , "TRUE"), new int[] { 0 });
wt.fc.QueryResult qr = wt.fc.PersistenceHelper.manager.find(qs);
if (qr.size() > 0) {
while (qr.hasMoreElements()) {
System.out.println("Query: "+qr.hasMoreElements());
user=(wt.doc.WTDocument) qr.nextElement();
System.out.println("Document = "+ user);
System.out.println("Número documento = "+ user.getContainerReference());
System.out.println("Life Cycle Atual do Documento = "+ user.getLifeCycleName());
break;
}
}
wt.lifecycle.LifeCycleTemplateReference lctr = wt.lifecycle.LifeCycleHelper.service.getLifeCycleTemplateReference("LC_DocumentoProduto", user.getContainerReference());
if(lctr == null){
throw new WTException("Life Cycle Not Found");
}else if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) lctr.getObject())){
throw new WTException("Life Cycle Template is checked out");
}
package com.anderson.testes;
import wt.doc.WTDocument;
import wt.fc.WTObject;
import wt.lifecycle.LifeCycleHelper;
import wt.lifecycle.LifeCycleManaged;
import wt.lifecycle.LifeCycleState;
import wt.lifecycle.LifeCycleTemplateReference;
import wt.org.WTPrincipal;
import wt.session.SessionHelper;
import wt.util.WTException;
public class WfTest {
public static void main(String[] args) {
wt.doc.WTDocument user = null;
String number = "OEP001-00-OEP-0000-DE-C121-0019";
try{
String obid = "VR:wt.doc.WTDocument:478422008:542998064-1353037556831-1605728400-85-120-154-10@oepsp039wi.odebrecht.net";
wt.fc.ReferenceFactory rf = new wt.fc.ReferenceFactory();
String[] array = org.apache.commons.lang.StringUtils.split(obid, ':');
wt.fc.WTReference ref = rf.getReference(array[0] + ":" + array[1] + ":" + array[2]);
System.out.println("Obj: "+ref.getObject());
user = (wt.doc.WTDocument) ref.getObject();
WTPrincipal getUser = SessionHelper.manager.getPrincipal();
wt.query.QuerySpec qs = new wt.query.QuerySpec(wt.doc.WTDocument.class);
qs.setAdvancedQueryEnabled(true);
// qs.appendWhere(new wt.query.SearchCondition(wt.doc.WTDocument.class, "master>number" , wt.query.SearchCondition.LIKE,number), new int[] { 0 });
qs.appendWhere(new wt.query.SearchCondition(WTDocument.class, WTDocument.BRANCH_IDENTIFIER, wt.query.SearchCondition.EQUAL, new Long(user.getBranchIdentifier())));
qs.appendAnd();
qs.appendWhere(new wt.query.SearchCondition(wt.doc.WTDocument.class, "iterationInfo.latest" , "TRUE"), new int[] { 0 });
wt.fc.QueryResult qr = wt.fc.PersistenceHelper.manager.find(qs);
if (qr.size() > 0) {
while (qr.hasMoreElements()) {
System.out.println("Query: "+qr.hasMoreElements());
user=(wt.doc.WTDocument) qr.nextElement();
System.out.println("Document = "+ user);
System.out.println("Número documento = "+ user.getContainerReference());
System.out.println("Life Cycle Atual do Documento = "+ user.getLifeCycleName());
break;
}
}
wt.lifecycle.LifeCycleTemplateReference lctr = wt.lifecycle.LifeCycleHelper.service.getLifeCycleTemplateReference("LC_DocumentoProduto", user.getContainerReference());
if(lctr == null){
throw new WTException("Life Cycle Not Found");
}else if(wt.vc.wip.WorkInProgressHelper.isCheckedOut((wt.vc.wip.Workable) lctr.getObject())){
throw new WTException("Life Cycle Template is checked out");
}
wt.lifecycle.LifeCycleManaged lcm = wt.lifecycle.LifeCycleHelper.service.reassign((wt.lifecycle.LifeCycleManaged) user, lctr, user.getContainerReference(), SPECIFIC STATE );
System.out.println("Novo Life Cycle = " + lcm.getLifeCycleName());
}catch(Exception e){
e.printStackTrace();
}
}
}
wt.lifecycle.LifeCycleManaged lcm = wt.lifecycle.LifeCycleHelper.service.reassign((wt.lifecycle.LifeCycleManaged) user, lctr, user.getContainerReference(), SPECIFIC STATE );
System.out.println("Novo Life Cycle = " + lcm.getLifeCycleName());
}catch(Exception e){
e.printStackTrace();
}
}
}
Solved! Go to Solution.
Hi Yogesh,
Following works on 10.0 M040
I can do using the following code:
wt.lifecycle.State emitido = wt.lifecycle.State.toState("EMITIDO");
wt.lifecycle.LifeCycleHelper.service.reassign(list, lctr, user.getContainerReference(), emitido);
Thank you!
Following works on 10.2 M10
final State canceledState = State.toState("CANCELLED");
wt.lifecycle.LifeCycleManaged lcm = wt.lifecycle.LifeCycleHelper.service.reassign((wt.lifecycle.LifeCycleManaged) user, lctr, user.getContainerReference(), canceledState );
Hi Yogesh,
Following works on 10.0 M040
I can do using the following code:
wt.lifecycle.State emitido = wt.lifecycle.State.toState("EMITIDO");
wt.lifecycle.LifeCycleHelper.service.reassign(list, lctr, user.getContainerReference(), emitido);
Thank you!