NOOB Using a Command to set column values on INSERT

Given you plan to use the Relativity server you cannot use the BusinessProcessor approach as in this topic: Can I get the record after Linq InsertRow() using C#

You’ll need to use the Scripting to achieve the similar result (ie server-calculated PrimaryKey field value).

F.e. let’s assume I have a Customers table (it can be found in the SQLite database C:\Users\Public\Documents\RemObjects Samples\Database\PCTrade.sqlite.db)
I need to have its ID field to be calculated on the server side.

THe 1st step is to enable the Server Autorefresh option for this field in the Schema Modeler:

Then go to the Scripts node for this table and define the following script:

// Called before each change is applied to the database
function beforeProcessDeltaChange(delta, change, wasRefreshed, canRemove)
{
	if (!change.isInsert) {
	  return;
	}
	
	// Query the database for a new ID value
	// Remember - this is DA SQL, not a real SQL
	var sql = 'SELECT COUNT(*) as newId FROM customers WHERE Name <> :pCustomerName';
	var params = { pCustomerName : 'Some Value' };
	var selectResult = lda.selectSQL(sql, params);
	var row = selectResult.nextRow();
	var newId = row['newId'] + 1;
	
	change.newValues['Id'] = 'CALC' + newId;
}

In this script a parametrized DA SQL is executed against the database and then the value returned by this script is used as a part of the primary key otf the record being inserted. Exactly the thing you need.

I can provide a full sample app if needed. If you want then you can give me the DDL of your table so the sample will be closer to exactly your case.