Insert records between companies using crosscompany keyword in Ax 2012

Direct

static void CompTest(Args _args)
{
CompTest ct;
;
changecompany(“CEE”)
{
ct.Name=”Krish”;

ct.insert();
}

}

From one company to another

static void CompTest1(Args _args)
{

CompTest ctfrom,ctto;
Container _ListOfLegalEntites =[“CEU”];
;

While select crosscompany:_ListOfLegalEntites * from ctfrom

{
changecompany(“CEE”)
{
ctto.Name=ctfrom.Name;

ctto.insert();
}

}

}

From one company to another using buf2buf

static void CompTestt(Args _args)
{
CompTest itFrom;

CompTest itTo;

select itFrom where itFrom.Name==”Great”;

changeCompany(“CEU”)

{

itTo = null;

buf2buf(itFrom, itTo);

itTo.insert();

}

}

 

Using X++ Query

static void CrossCOmpanyExample(Args _args)
{
CompTest ct;
Query q;
QueryRun qr;
QueryBuildDataSource qbds ;
;
q = new query();
qbds = q.addDataSource(tablenum(CompTest));

q.allowCrossCompany(true);
q.addCompanyRange(‘CEU’);
q.addCompanyRange(‘CEE’);

qr = new QueryRun(q);

while(qr.next())
{
ct = qr.get(tablenum(CompTest));
info(strfmt(“%1 — %2”,ct.Name,ct.dataAreaId));
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s