specify company in SETRANGE before DELETEALL

sam75sam75 Member Posts: 2
Hi Guys
I have seen code where SETRANGE include a company name or id when selecting a record set as below:
Object.SETRANGE(Type,Object.Type::TableData);
Object.SETRANGE("Company Name",COMPANYNAME);
Object.DELETEALL;
[img]https://us.v-cdn.net/5022383/uploads/editor/bi/xks0kbyt5ljw.png[/img]
Is this necessary as I haven't use a company filter before in BC SaaS
Thanks

Best Answers

  • BertVerbBertVerb Member Posts: 24
    Answer ✓
    That depends on the table records you want delete.
    In tablepercompany = no then you should do it.
    In other cases it depends.
  • vaprogvaprog Member Posts: 1,144
    edited 2022-03-16 Answer ✓
    Please note that the filter above is set on a table field named "Company Name". Most NAV tables do not have such a field, but instead have the property DataPerCompany set to it's default value which is Yes. This means, separate tables are maintained on SQL Server for each company. Unless you switch to accessing another company's data explicitly using the CHANGCOMPANY command, you only ever access the current company's data. So, no extra filtering is needed, or even possible. Even most tables that have DataPerCompany set to No do not usually have a field to filter for a company. You would rather set that property to Yes in the design of the table.

    The Object table used above is a special case. The objects in general are independent of a company. Only virtual pseudo objects of type TableData are company specific in that table. And I would strongly recommend against deleting table data using this table. You should rather use a record variable of the correct subtype (or a variable of type RecordRef, if you need more flexibility), and use that variable's DELETEALL method.

Answers

  • BertVerbBertVerb Member Posts: 24
    Answer ✓
    That depends on the table records you want delete.
    In tablepercompany = no then you should do it.
    In other cases it depends.
  • sam75sam75 Member Posts: 2
    Thanks
    I deleted without the company filter and as expected only applied to the logged in company (SaaS BC) but perhaps may not be the safest option
  • vaprogvaprog Member Posts: 1,144
    edited 2022-03-16 Answer ✓
    Please note that the filter above is set on a table field named "Company Name". Most NAV tables do not have such a field, but instead have the property DataPerCompany set to it's default value which is Yes. This means, separate tables are maintained on SQL Server for each company. Unless you switch to accessing another company's data explicitly using the CHANGCOMPANY command, you only ever access the current company's data. So, no extra filtering is needed, or even possible. Even most tables that have DataPerCompany set to No do not usually have a field to filter for a company. You would rather set that property to Yes in the design of the table.

    The Object table used above is a special case. The objects in general are independent of a company. Only virtual pseudo objects of type TableData are company specific in that table. And I would strongly recommend against deleting table data using this table. You should rather use a record variable of the correct subtype (or a variable of type RecordRef, if you need more flexibility), and use that variable's DELETEALL method.
Sign In or Register to comment.