Hi,
We have a database with +100 companies. For that reason i have created a codeunit to check if there is some gl accounts there are not in use. If it is in use on 1 of the companies its not allowed to get deleted.
My code looks like this.
I have run into trouble - I get a different result depending on if I run it from company A with no gl entries on the accounts versus if I run it from company B with gl entries in the accounts.
Its like my GlEnrty.FINDFIRST is only looking at the company I run the code from.
OnRun() counter_g := 0; GL.SETFILTER("No.", '78000|78005|78995'); IF GL.FIND('-') THEN BEGIN REPEAT IF CheckAccount(GL."No.",'*I/S') = 0 THEN BEGIN counter_g += 1; END; UNTIL GL.NEXT = 0; END; IF counter_g = 0 THEN BEGIN IF GL.FIND('-') THEN BEGIN REPEAT MESSAGE('Its safe to delete account if you reach this point.'); UNTIL GL.NEXT = 0; END; END; MESSAGE('Codeunit done.'); LOCAL CheckAccount(pAcc : Code[10];pCompanyFilter : Text[30]) counter1 : Integer counter1 := 0; CLEAR(RecCompany); RecCompany.SETFILTER(Name, '%1', pCompanyFilter); //ERROR('%1', RecCompany.COUNT); IF RecCompany.FIND('-') THEN REPEAT GL.CHANGECOMPANY(RecCompany.Name); MESSAGE(RecCompany.Name); IF GL.GET(pAcc) THEN BEGIN CLEAR(GLEntry); GLEntry.SETRANGE(GLEntry."G/L Account No.", pAcc); IF GLEntry.FINDFIRST THEN BEGIN text := 'Entry found in : ' + RecCompany.Name + ': account no. ' + pAcc + '\' + text; counter1 += 1; END; END; UNTIL RecCompany.NEXT = 0; IF text <> '' THEN MESSAGE(text);
*This post is locked for comments