Wednesday, July 3, 2013

Cross company traversing

Today's discussion is around traversing a table across companies. In our example, a record sits in a custom parameters table, which needs to be updated. Instinctively first thing to check would be  the SaveDataPerCompany property of the table, which in our case is set to Yes. So this table stores records per company and for implementing the feature in discussion we will forcefully update the record across all companies by overriding the table's update method.

Logic centers around
1. Traversing DataArea table, which is a system table containing all legal entities
2. Using keyword changeCompany which swaps the companies one by one and
3. Clearing the table object after each change, failing to do so makes the logic not work.

 public void update()   
 {   
   YourTable yourtable;  
   DataArea DataArea;   
   super();   
   while select DataArea where !DataArea.isVirtual   
   {   
     changecompany (DataArea.Id)   
     {   
       yourtable= null;   
       ttsBegin;   
       yourtable= Yourtable::find(true);        
       if (yourtable.RecId)   
       {   
         yourtable.Field = "";   
         yourtable.update();   
       }   
       ttsCommit;   
     }   
   }   
 }  

No comments:

Post a Comment