Felipe B. Duarte Silva's Profile
Agile User
95
Points

Questions
4

Answers
15

  • 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!

    This answer accepted by Felipe B. Duarte Silva. on May 11, 2024 Earned 15 points.

    • 1660 views
    • 4 answers
    • 1 votes
  • 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!

    • 1660 views
    • 4 answers
    • 1 votes
  • Hi Patrick,

    I,ve already looked the samples but could not find anything that could help me. 

    Thanks anyway!

    • 1231 views
    • 2 answers
    • 0 votes
  • Now, I have the groovy. It works for the first two blocks of get and set, but from the third one (ChpHObj) it stop working. I am suspecting the problem is because it is not string, it is numeric, but I don´t know how to fix that. Could you help me?

    The error I got is: No signature of method: com.agile.api.pc.item.Item.getValueByAttId() is applicable for argument types: (java.lang.Integer) values: [2012]

    The complete code is below, but for debbug I comment many lines to figure out the problem block by block.
    ———————
    import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
    import com.agile.agileDSL.ScriptObj.AgileDSLException;

    // add other import statements here
    import com.agile.api.ItemConstants;
    import com.agile.api.CommonConstants;
    import com.agile.api.IRow;
    import com.agile.api.IItem;
    import com.agile.api.IDataObject;
    import com.agile.api.ITable;
    import com.agile.px.IUpdateTableEventInfo;
    import com.agile.px.IEventInfo;
    import com.agile.api.IAgileSession;
    import com.agile.px.EventConstants;

    void invokeScript(IBaseScriptObj obj) {
    //script body starts here.

    //loop the AI table
    IAgileSession session = obj.getAgileSDKSession();
    IEventInfo req = obj.getPXEventInfo();

    try {
    int eventType=req.getEventType();
    int triggerType=req.getEventTriggerType();

    //The PX is only applicable for post update event
    if(eventType!=EventConstants.EVENT_UPDATE_TABLE || triggerType!=EventConstants.EVENT_TRIGGER_POST)
    return;

    IUpdateTableEventInfo info=(IUpdateTableEventInfo)req;
    IDataObject iProd = info.getDataObject();
    ITable tab = iProd.getTable(ItemConstants.TABLE_BOM);

    Iterator iter = tab.iterator();

    while (iter.hasNext()) {
    IRow row=(IRow)iter.next();

    String chItemNumber = row.getValue(ItemConstants.ATT_BOM_ITEM_NUMBER);
    IItem chItem = (IItem) session.getObject(ItemConstants.CLASS_ITEM_BASE_CLASS, chItemNumber);
    obj.logMonitor(chItemNumber);

    Object ChNumberObj = chItem.getValue(ItemConstants.ATT_TITLE_BLOCK_NUMBER);
    String ChNumber = ChNumberObj == null? “” : ChNumberObj.toString();
    obj.setValueByAttId(2472272, ChNumber);
    obj.logMonitor(ChNumber);

    Object ChDescriptionObj = chItem.getValue(ItemConstants.ATT_TITLE_BLOCK_DESCRIPTION);
    String ChDescription = ChDescriptionObj == null? “” : ChDescriptionObj.toString();
    obj.setValueByAttId(2000003231, ChDescription);
    obj.logMonitor(ChDescription);

    // Object ChpHObj = chItem.getValueByAttId(2012);
    // String ChpH = ChpHObj == null? “” : ChpHObj.toInteger();
    // obj.setValueByAttId(2012, ChpH);
    // obj.logMonitor(ChpH);

    // Object ChOdorThresholdObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_LIST31);
    // String ChOdorThreshold = ChOdorThresholdObj == null? “” : ChOdorThresholdObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT31, ChOdorThreshold);
    // obj.logMonitor(ChOdorThreshold);

    // Object ChApparentDensityObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT28);
    // String ChApparentDensity = ChApparentDensityObj == null? “” : ChApparentDensityObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT28, ChApparentDensity);
    // obj.logMonitor(ChApparentDensity);

    // Object ChDensityTemperatureObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT27);
    // String ChDensityTemperature = ChDensityTemperatureObj == null? “” : ChDensityTemperatureObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT27, ChDensityTemperature);
    // obj.logMonitor(ChDensityTemperature);

    // Object ChpHConditionObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT50);
    // String ChpHCondition = ChpHConditionObj == null? “” : ChpHConditionObj.toString();
    // obj.setValueByAttId(20000018783, ChpHCondition);
    // obj.logMonitor(ChpHCondition);

    // Object ChMeltingFreezingObj = chItem.getValueByAttId(2013);
    // String ChMeltingFreezing = ChMeltingFreezingObj == null? “” : ChMeltingFreezingObj.toString();
    // obj.setValueByAttId(2013, ChMeltingFreezing);
    // obj.logMonitor(ChMeltingFreezing);

    // Object ChFlashPointObj = chItem.getValueByAttId(2015);
    // String ChFlashPoint = ChFlashPointObj == null? “” : ChFlashPointObj.toString();
    // obj.setValueByAttId(2015, ChFlashPoint);
    // obj.logMonitor(ChFlashPoint);

    // Object ChControlledProductObj = chItem.getValueByAttId(2092);
    // String ChControlledProduct = ChControlledProductObj == null? “” : ChControlledProductObj.toString();
    // obj.setValueByAttId(2092, ChControlledProduct);
    // obj.logMonitor(ChControlledProduct);

    // Object ChNCMObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT36);
    // String ChNCM = ChNCMObj == null? “” : ChNCMObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT36, ChNCM);
    // obj.logMonitor(ChNCM);

    // Object ChHTSCODEUSObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT43);
    // String ChHTSCODEUS = ChHTSCODEUSObj == null? “” : ChHTSCODEUSObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT43, ChHTSCODEUS);
    // obj.logMonitor(ChHTSCODEUS);

    // Object ChCustomTariffClassMXObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT42);
    // String ChCustomTariffClassMX = ChCustomTariffClassMXObj == null? “” : ChCustomTariffClassMXObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT42, ChCustomTariffClassMX);
    // obj.logMonitor(ChCustomTariffClassMX);

    // Object ChIPIObj = chItem.getValueByAttId(12469);
    // String ChIPI = ChIPIObj == null? “” : ChIPIObj.toString();
    // obj.setValueByAttId(12469, ChIPI);
    // obj.logMonitor(ChIPI);

    // Object ChNALADIObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_TEXT37);
    // String ChNALADI = ChNALADIObj == null? “” : ChNALADIObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_TEXT37, ChNALADI);
    // obj.logMonitor(ChNALADI);

    // Object ChCertificationObj = chItem.getValueByAttId(2000008063);
    // String ChCertification = ChCertificationObj == null? “” : ChCertificationObj.toString();
    // obj.setValueByAttId(2000008063, ChCertification);
    // obj.logMonitor(ChCertification);

    // Object ChPhysicalStateObj = chItem.getValueByAttId(2025);
    // String ChPhysicalState = ChPhysicalStateObj == null? “” : ChPhysicalStateObj.toString();
    // obj.setValueByAttId(2025, ChPhysicalState);
    // obj.logMonitor(ChPhysicalState);

    // Object ChAppearanceObj = chItem.getValue(ItemConstants.ATT_PAGE_TWO_LIST35);
    // String ChAppearance = ChAppearanceObj == null? “” : ChAppearanceObj.toString();
    // obj.setValue(ItemConstants.ATT_PAGE_TWO_LIST35, ChAppearance);
    // obj.logMonitor(ChAppearance);

    // Object ChProductTypeObj = chItem.getValueByAttId(2023);
    // String ChProductType = ChProductTypeObj == null? “” : ChProductTypeObj.toString();
    // obj.setValueByAttId(2023, ChProductType);
    // obj.logMonitor(ChProductType);
    }

    }
    catch (Exception e) {
    e.printStackTrace();
    throw new AgileDSLException(e);
    } // end of try catch block
    }

    Thanks in advance!

    • 1413 views
    • 3 answers
    • 0 votes
    • 1413 views
    • 3 answers
    • 0 votes
  • Matt, thanks for the inputs.

    I will not have so many sites, the maximum is 10. But with your inputs I add some if inside the while and now it is working well without infinite loops.
    My script is not organized well but it is working. I am sure that there is a way to simplify this code but my knowledge in codes is not enough at all… 🙂

    One last improvement that I would like to do is auto-refresh the tab after running the code since everytime I add a new line at site tab I need to refresh the tab in order to have the value wrote at the attribute.

    Please see below the code which is working. I keep the trigger as Post and Synchronous.

    ——————————————–
    import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
    import com.agile.agileDSL.ScriptObj.AgileDSLException;

    // add other import statements here
    import com.agile.api.ItemConstants;
    import com.agile.api.CommonConstants;
    import com.agile.api.IRow;
    import com.agile.api.IItem;
    import com.agile.api.IDataObject;
    import com.agile.api.ITable;
    import com.agile.px.IUpdateTableEventInfo;
    import com.agile.px.IEventInfo;
    import com.agile.api.IAgileSession;
    import com.agile.px.EventConstants;

    void invokeScript(IBaseScriptObj obj) {
    //script body starts here.

    //loop the AI table
    IAgileSession session = obj.getAgileSDKSession();
    IEventInfo req = obj.getPXEventInfo();

    try {
    int eventType=req.getEventType();
    int triggerType=req.getEventTriggerType();

    //The PX is only applicable for post update event
    if(eventType!=EventConstants.EVENT_UPDATE_TABLE || triggerType!=EventConstants.EVENT_TRIGGER_POST)
    return;

    IUpdateTableEventInfo info=(IUpdateTableEventInfo)req;
    IDataObject iProd = info.getDataObject();
    ITable tab = iProd.getTable(ItemConstants.TABLE_BOM);

    Iterator iter = tab.iterator();

    while (iter.hasNext()) {
    IRow row=(IRow)iter.next();

    // Object ItemTypeObj = obj.getValueByAttId(ItemConstants.ATT_TITLE_BLOCK_ITEM_TYPE);
    // String ItemType = ItemTypeObj == null? “” : ItemTypeObj.toString();
    // obj.logMonitor(ItemType);

    Object ItemTypeBOMObj = row.getValue(ItemConstants.ATT_BOM_ITEM_TYPE);
    String ItemTypeBOM = ItemTypeBOMObj == null? “” : ItemTypeBOMObj.toString();
    // obj.logMonitor(ItemTypeBOM);

    Object ItemNumberjob = row.getValue(ItemConstants.ATT_BOM_ITEM_NUMBER);
    String ItemNumber = ItemNumberjob == null? “” : ItemNumberjob.toString();
    // obj.logMonitor(ItemNumber);

    String ProdNumber = obj.getValueByAttId(ItemConstants.ATT_TITLE_BLOCK_NUMBER);
    IItem item = (IItem) session.getObject(ItemConstants.CLASS_ITEM_BASE_CLASS, ProdNumber);
    // obj.logMonitor(ProdNumber);

    ITable tab2 = iProd.getTable(ItemConstants.TABLE_SITES);
    Iterator iter2 = tab2.iterator();

    if (ItemTypeBOM == ‘Chemical Item’) {
    // obj.logMonitor(“IF”);

    while (iter2.hasNext()){
    IRow rowa=(IRow)iter2.next();
    // set the CI Number at Sites Tab
    Object PCItemObj = rowa.getValue(ItemConstants.ATT_SITES_TEXT01);
    String PCItem = PCItemObj;
    // obj.logMonitor(“While” + “…” + PCItem + “…”);
    if (PCItem == ”){
    rowa.setValue(ItemConstants.ATT_SITES_TEXT01, ItemNumber);
    // obj.logMonitor(“Escreveu”)
    }
    else {
    // obj.logMonitor(“ELSE2”);
    continue;
    }

    }
    break;
    }
    else {

    while (iter2.hasNext()) {
    IRow rowa=(IRow)iter2.next();
    Object PCItemObj = rowa.getValue(ItemConstants.ATT_SITES_TEXT01);
    String PCItem = PCItemObj;
    if (PCItem == ”){
    rowa.setValue(ItemConstants.ATT_SITES_TEXT01, “N/A”);
    }
    else {
    // obj.logMonitor(“ELSE2”);
    continue;
    }
    }
    }

    }
    }
    catch (Exception e) {
    e.printStackTrace();
    throw new AgileDSLException(e);
    } // end of try catch block
    }
    ———-

    Thanks again everyone for helping.

    This answer accepted by Felipe B. Duarte Silva. on May 11, 2024 Earned 15 points.

    • 2729 views
    • 6 answers
    • 0 votes
  • It is a good idea, I will see which one works better.
    Thanks for all help!

    • 2729 views
    • 6 answers
    • 0 votes
  • Hi Steve,

    When I add a site for a product the script looks to items in BOM and depending on item type the script write one thing or another at an attribute on site table. According to what you said, and since the trigger is the auto update table, when I add a site to the table it auto update and the script runs. When the script run it auto update the table again and so on. Endless. The strange thing is that it occurs only at second line of the site table, for the first it works well.

    So, is there a way to fix it at the script?

    Just in case, the trigger Event Type is Update Table running only with a specific item (Product) and in the specific tab (sites). The trigger type is Post and it is executing Synchronous.

    Thanks in advance for helping.

    • 2729 views
    • 6 answers
    • 0 votes
  • Agile User Asked on October 27, 2017 in Agile PLM (v9).

    And just a important thing that I would like to add to this thread. I was using change status as Event trigger and because of that it was causing the loop. When I change the event trigger to approve for workflow everything works well. So thanks everyone who helped me.

    • 4166 views
    • 15 answers
    • 0 votes
  • Agile User Asked on October 26, 2017 in Agile PLM (v9).

    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.

    • 4166 views
    • 15 answers
    • 0 votes