Script PX – Nulling Affected Items on SaveAs

Hello – I am very, very rusty on writing Script PXs and am looking for input on the following scenario.

I am doing a SAVEAS from one Change Object to another. On the second change object (saveto), I would like to iterate through the affected items tab and null out a field for all items. Here is what I have – as you will see I only want this to occur when its a CR saved as another CR, thus the bottom IF statement. Would someone kindly provide some input on how to accomplish this?


import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.api.IChange;
import com.agile.api.IDataObject;
import com.agile.api.ITable;
import com.agile.api.IRow;
import com.agile.api.CommonConstants;
import com.agile.api.ChangeConstants;
import com.agile.api.ItemConstants;
import com.agile.agileDSL.ScriptObj.*;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.*

void invokeScript(IBaseScriptObj obj)
obj.logMonitor(“Entering invokeScript”);
obj.logMonitor(“Change #”+obj.getObjectNumber());
obj.logMonitor(“New #”+obj.getNewNumber());

// Get the CR and CO numbers
IChange savefrom = (IChange) obj.getAgileSDKSession().getObject(IChange.OBJECT_TYPE, obj.getObjectNumber());
IChange saveto = (IChange) obj.getAgileSDKSession().getObject(IChange.OBJECT_TYPE, obj.getNewNumber());

// Set the CO workflow

Integer savefromID =(Integer)(savefrom.getAgileClass().getSuperClass().getId());
Integer savetoID =(Integer)(saveto.getAgileClass().getSuperClass().getId());

//Check for saveas condition CR saved as a CO
if((savefromID.equals(ChangeConstants.CLASS_CHANGE_REQUESTS_CLASS)) && (savetoID.equals(ChangeConstants.CLASS_CHANGE_ORDERS_CLASS))) {
obj.logMonitor(“The source object is a CR.”);
obj.logMonitor(“The new object is a CO. “);
obj.logMonitor(“The Affected Items Tab will not be modified.”)
// Add the CR relationship to the CO relationships table
ITable relationships = saveto.getTable(CommonConstants.TABLE_RELATIONSHIPS);
IRow relationshipRow = relationships.createRow(savefrom);

//Check for saveas condition CR saved as a CR – if YES, null the desired fields on Affected Items tab
if((savefromID.equals(ChangeConstants.CLASS_CHANGE_REQUESTS_CLASS)) && (savetoID.equals(ChangeConstants.CLASS_CHANGE_REQUESTS_CLASS))) {
obj.logMonitor(“The source object is a CR.”);
obj.logMonitor(“The new object is a CR. “);
obj.logMonitor(“The Affected Items Tab will be modified.”)
// Iterate through Affected Items table




Agile User Asked on January 25, 2020 in Product Collaboration.
Add Comment
1 Answer(s)

I had a similar issue, where data from a ‘Save As’ did not get cleared.  But we decided to do it a different way.  The users were ok with this idea.  Clear a couple of dates on every Affected Item when the ECO went from Pending to Submitted.  This is the script.

// Purpose: Clear the Affected Items 'Effective Date' and 'Obsolete Date' when ECO status goes from Pending to Submitted.
// Event Subscriber: Event Type is 'Change Status for Workflow'. Object Type is 'ECO'
// Event: Workflow: specify the Workflow name. Object Type: 'ECO'. Status - From: 'Pending'. Status - To: 'Submitted'
// Event Handler Type: Script PX, groovy script, using Agile SDK
// -------------------------------------------

import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.*;
import java.util.*;
import com.agile.px.IEventInfo;
import com.agile.px.EventConstants;
import com.agile.px.IWFChangeStatusEventInfo;

void invokeScript(IBaseScriptObj obj) {

IAgileSession msession = obj.getAgileSDKSession();
IEventInfo req = obj.getPXEventInfo();
IWFChangeStatusEventInfo e = null;

try {
  if (req instanceof IWFChangeStatusEventInfo) {
    eventInfo = (IWFChangeStatusEventInfo)req;

// obj.logMonitor( "Chg nbr: " + obj.getObjectNumber());

  IChange pchange = (IChange) msession.getObject(IChange.OBJECT_TYPE, obj.getObjectNumber());

// obj.logMonitor( "ECO: " + (String) pchange.getValue(ChangeConstants.ATT_COVER_PAGE_NUMBER));

  ITable ai = pchange.getTable(ChangeConstants.TABLE_AFFECTEDITEMS);
  Iterator it = ai.iterator();
  IRow row = null;

  while(it.hasNext()) {
    row = (IRow);
    String m_eff_date = (String) row.getValue(ChangeConstants.ATT_AFFECTED_ITEMS_EFFECTIVE_DATE);
    if ( m_eff_date != null ) {
// obj.logMonitor( "not null Eff Date: " + m_eff_date );
      row.setValue(ChangeConstants.ATT_AFFECTED_ITEMS_EFFECTIVE_DATE, null);

    String m_obs_date = (String) row.getValue(ChangeConstants.ATT_AFFECTED_ITEMS_OBSOLETE_DATE);
    if ( m_obs_date != null ) {
// obj.logMonitor( "not null Obs Date: " + m_obs_date );
      row.setValue(ChangeConstants.ATT_AFFECTED_ITEMS_OBSOLETE_DATE, null);

} catch (APIException ex) {
obj.logMonitor(v_progress + ex.getMessage());

Agile Talent Answered on January 28, 2022.
Add Comment

Your Answer

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