x++


How can I loop over Tables which contain specific characters in their AOT name and delete the data?


I want to loop over a few tables where the name (aotName) begins with 'HbcCka', finally I want to delete all data from the tables.
Now I need a logic to empty the tables. How can I achieve this?
UPDATED:
static void tstDeleteForecastingData(Args _args)
{
Dictionary dictionary = new Dictionary();
int i;
SysDictTable dictTable;
;
for (i=1 ; i<=dictionary.tableCnt() ; i++)
{
if (strScan(tableid2name(dictionary.tableCnt2Id(i)), "HbcCka", 1, strLen(dictionary.tableName(i))))
{
info(strfmt('%1;%2', dictionary.tableCnt2Id(i), tableid2name( dictionary.tableCnt2Id(i) )));
}
}
}
Truncate the tables in all companies?
Use System Administration\Periodic\Databases\SQL Administration, mark the tables then choose Table actions\Truncate.
Or make a class with a server main method:
ClassDeclaration tstDeleteForecastingData
{
}
static server void main(Args _args)
{
Dictionary dictionary = new Dictionary();
int i;
for (i=1 ; i<=dictionary.tableCnt() ; i++)
{
if (strScan(tableid2name(dictionary.tableCnt2Id(i)), "HbcCka", 1, 99)))
{
info(strfmt('%1;%2', dictionary.tableCnt2Id(i), tableid2name( dictionary.tableCnt2Id(i) )));
new SqlDataDictionaryPermission(methodstr(SqlDataDictionary, tableTruncate)).assert();
new SqlDataDictionary().tableTruncate(dictionary.tableCnt2Id(i), false);
CodeAccessPermission::revertAssert();
}
}
}
If only in current company:
Common table = new DictTable(<tableId>).makeRecord();
table.skipDeleteMethod(true);
table.skipDeleteAction(true);
delete_from table;
To speed things up, you could use the stored procedure sp_msforeachtable to loop tables in the database (with a check on the table names) and just write your delete statement to delete records where the dataAreaId is the one you want.
Something like this can be use to delete the tables starting with HbcCka in the CEU company:
exec sp_msforeachtable '
if "?" like "HbcCka%"
delete from ? where DataAreaId = "CEU"
'

Related Links

group by clause in X++
Determine the number of affected rows by an update_recordset call in Dynamics 4.0?
how to protect the x++ source code
About Data Dictionary
setTimeOut and local function
Passing FromControl in a lookup override method
Reference control from datamethod in generated design
Extended EDT does not compare dates
How to display a tooltip in Dynamics AX 4.0?
how to disable intellisense in ax2012's code editor?
How do you “Run” a class
General quesions about Dynamics Ax
Convert date into julian date
How to change the level of AX info messages
X++ unbound control
WeekOfYear in X++ using .net lib

Categories

HOME
sonarqube
adal
spark-streaming
telegram
dns
webdriver
css3
swt
obfuscation
gradient
static-site
database-normalization
aws-cli
switch-statement
maxscript
echo
tvos
code-coverage
spin
syntaxnet
openstreetmap
minecraft-forge
cmdb
firefox-addon
spring-async
dataflow-diagram
react-toolbox
definitelytyped
surveymonkey
ms-access-web-app
nstimer
inversion-of-control
datastax-enterprise-graph
tpm
subclass
jaws
corenlp-server
custom-controls
zend-debugger
weather
jett
arduino-ide
slacktextviewcontroller
modernizr
flatmap
apns-php
escpos
postgresql-8.4
sharp-snmp
smoothstate.js
x++
puredata
fwrite
sonarlint-eclipse
aquamacs
scalding
qtranslate
semantic-logging
java-6
backbone-collections
excel-dna
dt
seq
janus
rsa-archer-grc
pocketsphinx-android
visual-studio-2008-sp1
hadoop-2.7.2
macaulay2
mta
jquery-jscrollpane
qiime
data-protection
asyncdisplaykit
maybe
dynamics-nav-2016
gocql
pypiserver
django-urls
sony-lifelog-api
branch-and-bound
rdflib
matlab-deployment
bufferedinputstream
ejb-2.x
delayed-execution
packet-sniffers
paw
functional-java
jquery-slider
fpdi
vbe
visual-studio-express
jammer
embedded-fonts
route-provider
scmmanager
patricia-trie
cuda-gdb
inkcanvas
azman
ilasm
jsr286
relative
inline-formset
eclipse-marketplace
pos-for-.net
request-headers
dsl-tools
fdf
technical-debt

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App