Copy table data on Intercompany with X++ code
Copy table data on Intercompany with X++ code.
Remark by Jimmy August 03th 2010
static void Jimmy_CopyTableDataIntercompany(Args _args)
{
int i;
Test FromTable,ToTable;
companyId formCompany,toCompany;
void buf2Buf(Common _from,Common _to)
{
DictTable dictTable = new DictTable(_from.TableId);
fieldId fieldId = dictTable.fieldNext(0);
while (fieldId && ! isSysId(fieldId))
{
_to.(fieldId) = _from.(fieldId);
fieldId = dictTable.fieldNext(fieldId);
}
}
;
formCompany = "NEW";
toCompany = "QCN";
ChangeCompany(formCompany)
{
FromTable = NULL; //must be this code
FromTable.clear();//must be this code
while select FromTable
{
i++;
changeCompany(toCompany)
{
ttsbegin;
ToTable = null;//must be this code
ToTable.clear(); //must be this code
ToTable.initValue();
buf2Buf(FromTable,ToTable);
ToTable.Qty = i;
ToTable.insert();
ttscommit;
}
}
}
}
/*
DictTable dicttable;
DictField dictfield;
int fieldcnt,i,m;
fieldId fieldid;
Test FromTable,ToTable;
;
global::buf2Buf(FromTable,ToTable);
ChangeCompany("New")
{
FromTable = null;
FromTable.clear();
while select FromTable
{
m++;
dicttable = new DictTable(FromTable.TableId);
changeCompany("qcn")
{
ToTable = null;
ToTable.clear();
ToTable.initValue();
fieldcnt = dicttable.fieldCnt();
for (i = 1; i <= fieldcnt; i++)
{
fieldid = dicttable.fieldCnt2Id(i);
dictfield = new dictfield(FromTable.TableId,fieldid);
if (dictfield.id() == fieldname2id(FromTable.TableId,identifierstr(DataAreaId)))
continue;
else
ToTable.(dictfield.id()) = FromTable.(dictfield.id());
}
ToTable.Qty = m;
ToTable.initValue();
ToTable.insert();
}
}
info(strfmt(int2str(m)));
}
*/

浙公网安备 33010602011771号