So I have a complete x++ script that aims to update records based on the retrieved result set made with select query with multiple joins and using crosscompany<
First off, do not try to do update cross company, it is bound to fail. Make the update work in current company, then apply the script to other relevant companies.
Fixed a few things:
Also put the update in an inner function, this will make it easy to update in more than one company. See this answer on how to do in all companies.
static void UpdateSample(Args _args)
{
void doIt()
{
InventTable a;
InventTableModule b;
EcoResProduct c;
EcoResProductCategory d;
EcoResCategory e;
EcoResCategoryHierarchy f;
int i;
ttsBegin;
while select a
join forUpdate b where a.ItemId == b.ItemId
exists join c where a.Product == c.RecId
exists join d where c.RecId == d.Product
exists join e where d.Category == e.RecId
exists join f where d.CategoryHierarchy == f.RecId
&& b.ModuleType == 2
&& b.LineDisc == ''
&& f.name == 'EXAMPLE'
&&(e.name == 'sample1' || e.name == 'sample2' || e.name == 'sample3')
{
++i;
b.LineDisc= 'something';
b.update();
}
ttsCommit;
info(strfmt("total record/s updated : %1", i));
}
changecompany ('XXX')
doIt();
}