// Sync Issue after upgrade Model store ax 2012 R3 TFS BUILD Process
Source :
http://dev.goshoom.net/en/2011/11/id-change/
https://community.dynamics.com/ax/f/33/p/209562/550639#550639
static void SyncIssue(Args _args)
{
Dictionary dictionary = new Dictionary();
SysDictTable dictTable;
DictField dictField;
TableId tableId;
FieldId fieldId;
Counter fieldCnt;
SqlDictionary sqlDictionaryTable;
SqlDictionary sqlDictionaryField;
setPrefix("Update of data dictionary IDs");
tableId = dictionary.tableNext(0);
ttsbegin;
while (tableId)
{
dictTable = new SysDictTable(tableId);
setPrefix(dictTable.name());
if ( dictTable.isSystemTable()
|| dictTable.isView()
|| dicttable.isTempDb()
|| dictTable.isTmp()
)
{
tableId = dictionary.tableNext(tableId);
continue;
}
///////////
//Finds table in SqlDictionary by name in AOT, if ID was changed.
//Empty field ID represents a table.
select sqlDictionaryTable
where sqlDictionaryTable.name == dictTable.name()
&& sqlDictionaryTable.fieldId == 0
&& sqlDictionaryTable.tabId != dictTable.id();
if (sqlDictionaryTable)
{
//Updates table ID in SqlDictionary
if (ReleaseUpdateDB::changeTableId(
sqlDictionaryTable.tabId,
dictTable.id(),
dictTable.name()))
{
info(strFmt("Table ID changed (%1 -> %2)", sqlDictionaryTable.tabId, dictTable.id()));
}
}
////////////
// Delete Fields that no more exists in AOT
while select forUpdate sqlDictionaryTable
where sqlDictionaryTable.tabId == dictTable.id()
&& sqlDictionaryTable.fieldId
{
If ( ! dictTable.fieldName2Id( sqlDictionaryTable.name ) )
{
sqlDictionaryTable.delete();
}
}
////////////
//fieldId = dictTable.fieldNext(0);
fieldCnt = dictTable.fieldCnt();
fieldId = dictTable.fieldCnt2Id(fieldCnt);
//For all fields in table
while (fieldCnt)
{
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSql() && !dictField.isSystem())
{
//Finds fields in SqlDictionary by name and compares IDs
select sqlDictionaryField
where sqlDictionaryField.tabId == dictTable.id()
&& sqlDictionaryField.name == dictField.name()
&& sqlDictionaryField.fieldId != 0
&& sqlDictionaryField.fieldId != dictField.id();
if (sqlDictionaryField)
{
//Updates field ID in SqlDictionary
if (ReleaseUpdateDB::changeFieldId(
dictTable.id(),
sqlDictionaryField.fieldId,
dictField.id(),
dictTable.name(),
dictField.name()))
{
info(strFmt("Field %1 - ID changed (%2 -> %3)",
dictField.name(),
sqlDictionaryField.fieldId,
dictField.id()));
}
}
}
//fieldId = dictTable.fieldNext(fieldId);
fieldCnt--;
fieldId = dictTable.fieldCnt2Id(fieldCnt);
}
tableId = dictionary.tableNext(tableId);
}
ttscommit;
}
Source :
http://dev.goshoom.net/en/2011/11/id-change/
https://community.dynamics.com/ax/f/33/p/209562/550639#550639
static void SyncIssue(Args _args)
{
Dictionary dictionary = new Dictionary();
SysDictTable dictTable;
DictField dictField;
TableId tableId;
FieldId fieldId;
Counter fieldCnt;
SqlDictionary sqlDictionaryTable;
SqlDictionary sqlDictionaryField;
setPrefix("Update of data dictionary IDs");
tableId = dictionary.tableNext(0);
ttsbegin;
while (tableId)
{
dictTable = new SysDictTable(tableId);
setPrefix(dictTable.name());
if ( dictTable.isSystemTable()
|| dictTable.isView()
|| dicttable.isTempDb()
|| dictTable.isTmp()
)
{
tableId = dictionary.tableNext(tableId);
continue;
}
///////////
//Finds table in SqlDictionary by name in AOT, if ID was changed.
//Empty field ID represents a table.
select sqlDictionaryTable
where sqlDictionaryTable.name == dictTable.name()
&& sqlDictionaryTable.fieldId == 0
&& sqlDictionaryTable.tabId != dictTable.id();
if (sqlDictionaryTable)
{
//Updates table ID in SqlDictionary
if (ReleaseUpdateDB::changeTableId(
sqlDictionaryTable.tabId,
dictTable.id(),
dictTable.name()))
{
info(strFmt("Table ID changed (%1 -> %2)", sqlDictionaryTable.tabId, dictTable.id()));
}
}
////////////
// Delete Fields that no more exists in AOT
while select forUpdate sqlDictionaryTable
where sqlDictionaryTable.tabId == dictTable.id()
&& sqlDictionaryTable.fieldId
{
If ( ! dictTable.fieldName2Id( sqlDictionaryTable.name ) )
{
sqlDictionaryTable.delete();
}
}
////////////
//fieldId = dictTable.fieldNext(0);
fieldCnt = dictTable.fieldCnt();
fieldId = dictTable.fieldCnt2Id(fieldCnt);
//For all fields in table
while (fieldCnt)
{
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSql() && !dictField.isSystem())
{
//Finds fields in SqlDictionary by name and compares IDs
select sqlDictionaryField
where sqlDictionaryField.tabId == dictTable.id()
&& sqlDictionaryField.name == dictField.name()
&& sqlDictionaryField.fieldId != 0
&& sqlDictionaryField.fieldId != dictField.id();
if (sqlDictionaryField)
{
//Updates field ID in SqlDictionary
if (ReleaseUpdateDB::changeFieldId(
dictTable.id(),
sqlDictionaryField.fieldId,
dictField.id(),
dictTable.name(),
dictField.name()))
{
info(strFmt("Field %1 - ID changed (%2 -> %3)",
dictField.name(),
sqlDictionaryField.fieldId,
dictField.id()));
}
}
}
//fieldId = dictTable.fieldNext(fieldId);
fieldCnt--;
fieldId = dictTable.fieldCnt2Id(fieldCnt);
}
tableId = dictionary.tableNext(tableId);
}
ttscommit;
}
No comments:
Post a Comment