Today we will see a code, which is useful to copy data from one table to a similar table and let's say you have many fields.
public static Common copyFromToTable(Common _commonFrom, Common _commonTo)
{
SysDictTable dictTable = new SysDictTable(_commonTo.TableId);
SysDictField dictField;
FieldId fieldId = dictTable.fieldNext(0);
while (fieldId)
{
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSql() && !dictField.isSystem())
{
FieldName fieldName = dictField.name();
FieldId fieldIdFrom = fieldName2Id(_commonFrom.TableId, fieldName);
if (fieldIdFrom)
{
_commonTo.(dictField.id()) = _commonFrom.(fieldIdFrom);
}
}
fieldId = dictTable.fieldNext(fieldId);
}
return _commonTo;
}
public static Common copyFromToTable(Common _commonFrom, Common _commonTo)
{
SysDictTable dictTable = new SysDictTable(_commonTo.TableId);
SysDictField dictField;
FieldId fieldId = dictTable.fieldNext(0);
while (fieldId)
{
dictField = dictTable.fieldObject(fieldId);
if (dictField.isSql() && !dictField.isSystem())
{
FieldName fieldName = dictField.name();
FieldId fieldIdFrom = fieldName2Id(_commonFrom.TableId, fieldName);
if (fieldIdFrom)
{
_commonTo.(dictField.id()) = _commonFrom.(fieldIdFrom);
}
}
fieldId = dictTable.fieldNext(fieldId);
}
return _commonTo;
}
No comments:
Post a Comment