Changing the table inheritance of a record must be done on SQL level – the following code does this. Of course, related data must be handled as well.
static void Job1(Args _args)
{
//change to product master
class1::changeInheritance('EcoResProduct',tableNum(EcoResProductMaster),EcoResProduct::findByDisplayProductNumber('0119').RecId);
//change back
//class1::changeInheritance('EcoResProduct',tableNum(EcoResDistinctProduct),EcoResProduct::findByDisplayProductNumber('0119').RecId);
}
//Important: this code must be run on the server
public static server void changeInheritance(str _tableName, tableId _newTableId, RefRecId _refRecId)
{
Connection connection;
Statement statement;
str query;
;
// create connection object
connection = new Connection();
// create statement
statement = connection.createStatement();
// Set the SQL statement
query = strfmt("update %1 set %1.InstanceRelationType ='%2' where %1.RecId = %3;", _tableName, _newTableId, _refRecId);
info(query);
// assert SQL statement execute permission
new SqlStatementExecutePermission(query).assert();
//BP Deviation documented
statement.executeUpdate(query);
// limit the scope of the assert call
CodeAccessPermission::revertAssert();
}

Leave a Reply