Using x++ code updated to system filed values
The following X++ code using to update system field values.
Wrote by Jimmy Jan 20th 2011
1)Add the Static method(UpdateupdateSystemFieldValues) to the global class.
static server void updateSystemFieldValues(common _common, int _systemFieldNum, anytype _fieldvalue) { Dictfield _dictField = new Dictfield(_common.TableId,_systemFieldNum); ; if (!_dictField) return; if (_dictField.isSystem()) { new OverwriteSystemfieldsPermission().assert(); _common.overwriteSystemfields(true); _common.(_systemFieldNum) = _fieldValue; CodeAccessPermission::revertAssert(); _common.overwriteSystemfields(false); } else { _common.(_systemFieldNum) = _fieldValue; } }
2)Job invoking the global static method updateSystemFieldValues
static void Jimmy_UpdateupdateSystemFieldValues(Args _args) { salesTable salesTable; ; ttsbegin; select firstonly forupdate salesTable where salesTable.createdBy == "tyler"; if(salesTable) { info(strfmt("%1 - %2 - %3",salesTable.SalesId,salesTable.createdBy,salesTable.RecId)); global::UpdateupdateSystemFieldValues(salesTable,fieldnum(SalesTable,createdby),"Jimmy"); salesTable.update(); } ttscommit; }