Convert Product to Product master

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
    //change back
//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);
    // assert SQL statement execute permission
    new SqlStatementExecutePermission(query).assert();
    //BP Deviation documented
    // limit the scope of the assert call

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s