I have a groovy where I need to set the workflow on save as but for some reason I can´t get the object.
As explained at the title, please see my groovy:
import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.DeclarationConstants;
import com.agile.api.IAgileSession;
import com.agile.px.IEventInfo;
import com.agile.px.EventConstants;
import com.agile.api.IItem;
import com.agile.api.IDeclaration;
void invokeScript(IBaseScriptObj obj) {
String newNumber = obj.getNewNumber();
obj.logMonitor(newNumber + ‘|’);
IAgileSession session = obj.getAgileSDKSession();
IEventInfo req = obj.getPXEventInfo();
IDeclaration dec = (IDeclaration) session.getObject(DeclarationConstants.CLASS_SUBSTANCE_DECLARATIONS_CLASS, newNumber);
obj.logMonitor(dec + ‘|’);
try {
int eventType=req.getEventType();
int triggerType=req.getEventTriggerType();
// The PX is only applicable for post update event
if(eventType!=EventConstants.EVENT_SAVE_AS_OBJECT || triggerType!=EventConstants.EVENT_TRIGGER_PRE)
return;
Object DeclarationTypeObj = obj.getValueByAttId(DeclarationConstants.ATT_COVER_PAGE_DECLARATION_TYPE);
String DeclarationType = DeclarationTypeObj == null? “” : DeclarationTypeObj.toString();
obj.logMonitor(DeclarationType + ‘|’);
obj.setValueByAttId(DeclarationConstants.ATT_COVER_PAGE_WORKFLOW, DeclarationType)
newWorkflow = obj.getValueByAttId(DeclarationConstants.ATT_COVER_PAGE_WORKFLOW);
// log para o Event Handler Monitor
obj.logMonitor(newWorkflow);
} catch (Exception e)
{
e.printStackTrace();
throw new AgileDSLException(e);
} // end of try catch block
} // end of invokeScript
It completes the groovy but for some reason the getobject is returning NULL as you can see at the message generated by the log monitor:
MD00119|null|Substance Declaration|Substance Declaration
Thanks in advance.
Did you try setting this up as a post synchronous event? You are trying to use a Pre event during a Save As. So, technically the object is not created yet.
Hello,
It is running as post since the code says:
if(eventType!=EventConstants.EVENT_SAVE_AS_OBJECT || triggerType!=EventConstants.EVENT_TRIGGER_PRE)
If it was running as pre it will even run the code.
Thanks!
Can you try changing this section FROM:
Object DeclarationTypeObj = obj.getValueByAttId(DeclarationConstants.ATT_COVER_PAGE_DECLARATION_TYPE);
String DeclarationType = DeclarationTypeObj == null? “” : DeclarationTypeObj.toString();
obj.logMonitor(DeclarationType + ‘|’);
TO:
String DeclarationTypeObj = obj.getValueByAttId(DeclarationConstants.ATT_COVER_PAGE_DECLARATION_TYPE);
obj.logMonitor(DeclarationTypeObj + ‘|’);
…and see what happens?
Option 2:
String DeclarationTypeObj = dec.getValue(DeclarationConstants.ATT_COVER_PAGE_DECLARATION_TYPE);
obj.logMonitor(DeclarationTypeObj + ‘|’);
Option 2 here uses the IDeclaration you got earlier. I’m confident at least option 2 will work for you.
Hi Matt,
First of all thanks for the suggestion.
With your suggestion plus some little modifications the code works. Now the groovy is:
Start:
import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.DeclarationConstants;
import com.agile.api.IAgileSession;
import com.agile.px.IEventInfo;
import com.agile.px.EventConstants;
import com.agile.api.IItem;
import com.agile.api.IDeclaration;
void invokeScript(IBaseScriptObj obj) {
String newNumber = obj.getNewNumber();
obj.logMonitor(newNumber + “|”);
IAgileSession session = obj.getAgileSDKSession();
IEventInfo req = obj.getPXEventInfo();
IDeclaration dec = (IDeclaration) session.getObject(DeclarationConstants.CLASS_SUBSTANCE_DECLARATIONS_CLASS, newNumber);
try {
int eventType=req.getEventType();
int triggerType=req.getEventTriggerType();
// The PX is only applicable for post update event
if(eventType!=EventConstants.EVENT_SAVE_AS_OBJECT || triggerType!=EventConstants.EVENT_TRIGGER_POST)
return;
Object DeclarationTypeObj = dec.getValue(DeclarationConstants.ATT_COVER_PAGE_DECLARATION_TYPE);
String DeclarationType = DeclarationTypeObj == null? “” : DeclarationTypeObj.toString();
obj.logMonitor(DeclarationType + “|”);
dec.setValue(DeclarationConstants.ATT_COVER_PAGE_WORKFLOW, DeclarationType)
newWorkflow = obj.getValueByAttId(DeclarationConstants.ATT_COVER_PAGE_WORKFLOW);
// log para o Event Handler Monitor
obj.logMonitor(newWorkflow);
}
catch (Exception e) {
e.printStackTrace();
throw new AgileDSLException(e);
} // end of try catch block
} // end of invokeScript
End
Thanks a lot everyone!