Please some one help me through code need to change the workflow status
Hello,
Could you please provide a example code with the initial steps as well? How to load the change and set the Workflow?
Thanks!
Hi,
Follow along the sample , i just added a sample for loading a change and moving to a particular status. You can also follow along the above sample if you want to move to default next status and notify the user along the way.
import com.agile.api.*;
public class ChangeStatusJava {
/**
* @param args
*/
private static String url = “EnterYourServerURL”; /
private static String username = “EnterUserName”;
private static String password = “Password”;
public static IAgileSession m_session = null; /
public static AgileSessionFactory m_factory = null;
public static IChange deviation = null;
private static String mailServer = null;
private static String mailFrom = “arifkhan@juniper.net”;
private static String adminEmail = null;
public static String expirationSucess = null;
public static String CHANGE_NUMBER= “EnterYourChangeNumber”;
public static void main(String[] args) {
try {
m_session = connectAgile(url, username, password);
if (m_session != null)
{
IChange m_change = (IChange) m_session.getObject(ChangeConstants.CLASS_CHANGE_BASE_CLASS,CHANGE_NUMBER);
/* You can try this syntax as well to load the change.
IChange m_change = (IChange) m_session.getObject(IChange.OBJECT_TYPE,CHANGE_NUMBER);
*/
m_session.disableAllWarnings(); //Disable all warnings.
m_change.changeStatus(m_change.getWorkflow().getStates(StatusConstants.TYPE_COMPLETE)[0], false,””, false, false, null, null, null, null, false);
//You can specify StatusConstants.TYPE_RELEASED –> Workflow Status of Type Release , TYPE_COMPLETE –> Workflow Status of Type Complete,
//You can accordingly specify change status TYPE_SUBMIT, TYPE_REVIEW,TYPE etc.
m_session.enableAllWarnings();
}
}
catch (APIException e) {
// TODO: handle exception
obj_logger.error(“Error while expiring deviation” + e.getMessage());
e.printStackTrace();
}
finally {
obj_logger.info(“==================== Execution of code is finished. ==============================”);
}
}
public static final IAgileSession connectAgile(String url, String userid, String password) throws APIException {
// TODO Auto-generated method stub
m_factory = AgileSessionFactory.refreshInstance(url);
HashMap<Integer, String> params = new HashMap<Integer, String>();
params.put(AgileSessionFactory.USERNAME, userid);
params.put(AgileSessionFactory.PASSWORD, password);
m_session = m_factory.createSession(params);
return m_session;
}
}
Arif, thanks a lot for answer this!
I think my problem is different. I need a groovy which will change the Workflow to cancel or released depeding on the value of a change attribute.
For example: If the value of attribute x = accepted than, after the event trigger, workflow status should change to released. If the value of attribute x = denied than the workflow status should change to Canceled.
I could make it almost work using setAttributebyValue but it not work since the workflow status cannot be change in this way since there is no permission to change. I think I need to use something like changeStatus(Released), but I do not know how.
Could you please help me?
Thanks in advance!
Workflow can’t be set by .setAttributeByValueId() but by the IRoutable .changeStatus() method Arif mentioned. Your groovy script will be something like:
if (change.getValue(ChangeConstants.ATT_PAGE_TWO_LIST01) == “Accepted” ) {
change.changeStatus() //fill in with the default inputs like Arif used above telling Agile to change the workflow to Released
}
else if (change.getValue(ChangeConstants.ATT_PAGE_TWO_LIST01) == “Denied” ) {
change.changeStatus() //sends the ECO to cancelled, just again make sure you fill in the correct inputs lest you get a “no signature of method” exception
}
There’s a bunch of ways to configure this. Does this help?
(I also recommend not using a Change Request attribute of ‘Denied’ as a Cancelled status type, though. Use Approved/Disapproved as both Complete types. Just a thought though).
Hi Matt,
First of all, thanks for helping.
I think we are almost there but the code still not work.
Here is the code I am using:
import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.ChangeConstants;
import com.agile.api.CommonConstants;
import com.agile.api.IAdmin;
import com.agile.api.IAgileClass;
import com.agile.api.IAgileList;
import com.agile.api.IAgileSession;
import com.agile.api.ICell;
import com.agile.api.IChange;
import com.agile.api.IDataObject;
import com.agile.api.IItem;
import com.agile.api.IProject;
import com.agile.api.IRow;
import com.agile.api.INode;
import com.agile.api.ITable;
import com.agile.api.IStatus;
import com.agile.px.ISignOffEventInfo;
import com.agile.px.EventActionResult;
import com.agile.px.ActionResult;
import com.agile.px.IEventAction;
import com.agile.px.IEventInfo;
import com.agile.px.IUpdateTableEventInfo;
import com.agile.px.EventConstants;
import com.agile.px.IEventDirtyTable;
import com.agile.px.IEventDirtyRowUpdate;
import com.agile.px.IEventDirtyCell;
// add other import statements here
void invokeScript(IBaseScriptObj change) {
//script body starts here
Object AttributeObj = change.getValueByAttId(CommonConstants.ATT_PAGE_THREE_LIST01)
String Attribute = AttributeObj == null? “” : AttributeObj.toString()
change.logMonitor(AttributeObj)
Object Status = change.getValueByAttId(ChangeConstants.ATT_COVER_PAGE_STATUS)
change.logMonitor(Status)
if (AttributeObj == ‘Accepted’ ) {
change.changeStatus(change.getWorkflow().getStates(StatusConstants.TYPE_RELEASED)[0], false,””, false, false, null, null, null, null, false)
}
else if (AttributeObj == ‘Denied’ ) {
change.changeStatus(change.getWorkflow().getStates(StatusConstants.TYPE_CANCELED)[0], false,””, false, false, null, null, null, null, false)
}
}
Here is the error in monitor:
No such property: StatusConstants for class: Change RAP Workflow Status
Can you help me?
Thanks in Advance.
It’s because you haven’t imported that specific library. Add import com.agile.api.StatusConstants to the top import section and try that.
You have more import statements than you need, by the way. The main ones you will need in your script moving forward will be:
import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.api.ChangeConstants;
import com.agile.api.CommonConstants;
import com.agile.api.IAgileSession
import com.agile.api.IChange
import com.agile.api.IRoutable
import com.agile.api.StatusConstants;
Let me know how it works because I highly suspect that it will not. You used the word ‘change’ in your script and there’s a difference in the behind-the-curtain logic in what you’re doing (IBaseScriptObj versus IChange dataobject). Some methods like .logMonitor use the IBaseScriptObj while others, like .getStatus() use the IChange dataobject and SDK session. For an example, see the “Add Document to New Part” script example in the Agile admin manual and how it uses the words ‘obj’, ‘session’, ‘part’, and ‘doc’. It’s good that you’re learning.
So, as you expected it does not work. The error is:
No signature of method: java.lang.String.getStates() is applicable for argument types: (com.agile.api.StatusConstants) values: [3:TYPE_RELEASED]
Possible solutions: getBytes(), getBytes(java.lang.String), getBytes(java.nio.charset.Charset), getClass(), getChars()
The Event trigger is Change Status and it is triggered by the Acknowledge button.
Yep, you’re answer is not as simply as you hope and you’re not as close as you first thought. That’s ok – I remember thinking I was close but then really wasn’t at all.
A few things to consider:
First – your .getStates method is correct but it’s working off of the wrong type of data. As far as Agile is concerned, it’s trying to work off of an IBaseScriptObj called “change”, but that data isn’t what you need. You need an IChange dataobject instead. There is a better way to get the data object, but for now, do this. Add these lines to the script and change the word “change” in the line starting with ‘void’ to this:
void invokeScript(IBaseScriptObj obj) {
IAgileSession session = obj.getAgileSDKSession();
String econumber = obj.getValueByAttId(ChangeConstants.ATT_COVER_PAGE_NUMBER);
IChange change = (IChange) session.getObject(ChangeConstants.CLASS_ECO, econumber)
You’ll need this line also early in the script after the void line:
IAgileSession session = obj.getAgileSDKSession();
Here we told Agile to run the invokeScript method off of the inherit object, then create our own mini-SDK session, get the object’s number, and then get the IChange change dataobject to do stuff with.
These four lines in your script aren’t doing anything important, if you want to remove them.
String Attribute = AttributeObj == null? “” : AttributeObj.toString()
change.logMonitor(AttributeObj)
Object Status = change.getValueByAttId(ChangeConstants.ATT_COVER_PAGE_STATUS)
change.logMonitor(Status)
(change.logMonitor() would hence need to be changed to obj.logMonitor() to work)
Note again in this new version of your script how the words ‘obj’, ‘session’, and ‘change’ all link together.