want groovy script to create change order auto number by referring affected item or relation ship item

i want to create change order /change request change number should be derived from “affected Item” and other seinario  need code to create change number from “relation ship Item”,

pleases let us know the groovy script if some body worked on this

No Files Were Attached
mahign Agile User Asked on February 6, 2019 in Product Collaboration.

//my groovy code to create change order and get affected Item description and set to change order description, but not getting desired result, ie change order “description of change” not getting updated

import java.sql.CallableStatement
import java.sql.Connection
import java.sql.DriverManager
import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.*
import com.agile.px.EventConstants
import com.agile.px.ICreateEventInfo
import com.agile.px.IEventInfo
import com.agile.px.ISaveAsEventInfo
import com.agile.api.IUser
import com.agile.api.IDataObject;
import com.agile.px.IUpdateTitleBlockEventInfo;
import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import java.util.*;

void invokeScript(IBaseScriptObj obj) {doAction(obj) }

public void doAction(IBaseScriptObj obj)throws java.lang.Exception, com.agile.api.APIException 
{ IEventInfo eventInfo = obj.getPXEventInfo();
IAgileSession session = obj.getAgileSDKSession()
IEventInfo req = obj.getPXEventInfo();
int eventType = eventInfo.getEventType();

if (eventType ==EventConstants.EVENT_CREATE_OBJECT)
{ IAgileClass objClass=session.getAdminInstance().getAgileClass(((ICreateEventInfo)eventInfo).getNewSubclassId());
IChange item = session.getObject(IChange.OBJECT_TYPE,((ICreateEventInfo)eventInfo).getNewNumber());
IDataObject dataObject = eventInfo.getDataObject();

// Iterate through Affected Items table
ITable ai = dataObject.getTable(ChangeConstants.TABLE_AFFECTEDITEMS);
Iterator it = ai.iterator();
IRow row = null;
while(it.hasNext()) {
row = (IRow)it.next();
String des = (String)row.getValue(ChangeConstants.ATT_AFFECTED_ITEMS_ITEM_DESCRIPTION);
item.setValue(“descriptionOfChange”, des);

obj.logMonitor(“Description Updated Successfully.”)}}}

on February 7, 2019.

hi Angels please review this script and let me know the issue

on February 10, 2019.
Add Comment
1 Answer(s)
Best answer

Is there a part of the coding you need help with? I assume you’re already familiar with how to write Groovy scripts and work with the SDK in general.

keithrust Agile Angel Answered on February 6, 2019.

Hi Keithrust,
I need code to iterate affected item and get certain attributes values to change order when create event of change order

on February 7, 2019.

hi my groovy code to create change order and get affected Item description and set change order description is this but not getting required result, ie change order description of change not getting updated

import java.sql.CallableStatement
import java.sql.Connection
import java.sql.DriverManager
import com.agile.agileDSL.ScriptObj.IBaseScriptObj;
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import com.agile.api.*
import com.agile.px.EventConstants
import com.agile.px.ICreateEventInfo
import com.agile.px.IEventInfo
import com.agile.px.ISaveAsEventInfo
import com.agile.api.IUser
import com.agile.api.IDataObject;
import com.agile.px.IUpdateTitleBlockEventInfo;
import com.agile.agileDSL.ScriptObj.IBaseScriptObj
import com.agile.agileDSL.ScriptObj.AgileDSLException;
import java.util.*;

void invokeScript(IBaseScriptObj obj) {doAction(obj) }

public void doAction(IBaseScriptObj obj)throws java.lang.Exception, com.agile.api.APIException 
{ IEventInfo eventInfo = obj.getPXEventInfo();
IAgileSession session = obj.getAgileSDKSession()
IEventInfo req = obj.getPXEventInfo();
int eventType = eventInfo.getEventType();

if (eventType ==EventConstants.EVENT_CREATE_OBJECT)
{ IAgileClass objClass=session.getAdminInstance().getAgileClass(((ICreateEventInfo)eventInfo).getNewSubclassId());
IChange item = session.getObject(IChange.OBJECT_TYPE,((ICreateEventInfo)eventInfo).getNewNumber());
IDataObject dataObject = eventInfo.getDataObject();

// Iterate through Affected Items table
ITable ai = dataObject.getTable(ChangeConstants.TABLE_AFFECTEDITEMS);
Iterator it = ai.iterator();
IRow row = null;
while(it.hasNext()) {
row = (IRow)it.next();
String des = (String)row.getValue(ChangeConstants.ATT_AFFECTED_ITEMS_ITEM_DESCRIPTION);
item.setValue(“descriptionOfChange”, des);

obj.logMonitor(“Description Updated Successfully.”)}}}

on February 7, 2019.

Are you running this as a pre or post event? I assume that there are no errors generated and you have debugged the code to know it’s going through the affected items iterator, correct? Have you tried using a change constant vs. API name for the description field?

on February 7, 2019.

Hi,
this is post event, no error log, 
please let me know where to use API Name ? 
dataObject.getTable(ChangeConstants.TABLE_AFFECTEDITEMS); or

(String)row.getValue(ChangeConstants.ATT_AFFECTED_ITEMS_ITEM_DESCRIPTION);

on February 8, 2019.

used API name but result not updated, 

ITable ai = dataObject.getTable(ChangeConstants.TABLE_AFFECTEDITEMS);
Iterator it = ai.iterator();
IRow row = null;
while(it.hasNext()) {
row = (IRow)it.next();
//ai_item = (IItem)row.next();

String it_cat =(String) row.getValue(“itemType”);
IItem mat = (IItem) session.getObject(IItem.OBJECT_TYPE,it_cat);
itm.setValue(“descriptionOfChange”,it_cat);
}
obj.logMonitor(“Description Updated Successfully.”);

}}

on February 8, 2019.
Add Comment

Your Answer

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