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.

No Files Were Attached
Felipe B. Duarte Silva Agile User Asked on March 12, 2018 in Other APIs.
Add Comment
4 Answer(s)

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.

https://www.agileplmexperts.com Agile Angel Answered on May 4, 2018.
Add Comment

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!

Felipe B. Duarte Silva Agile User Answered on May 4, 2018.
Add Comment

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.

Matt Paulhus Agile Expert Answered on May 4, 2018.
Add Comment
Best answer

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!

Felipe B. Duarte Silva Agile User Answered on May 7, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.