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

Clients seem to be running old (buggy) code after XPO project import
Number sequence AX 2012
SSRS MS words report with page break
How can you get a detailed error descriptions in Dynamics AX?
How to get the length of an array?
X++ loop through lines in grid control
Concatenating row values in x++
How do you access a macro in the AOT macro node?
How can I set the Backgoundcolor of an AX2012 Action Pane Button
How to Edit address using X++ in AX 2012
Number sequence issue Ax 2012?
Find code that's running in a Batch Job
What is the _isMexican boolean for in the Global::Checkpower method?
AlwaysOnTop property not behaving properly
Boolean AND logic in Microsoft Dynamics AX 2012 AIF QueryCriteria
Table: PrintMgmtSettings Field: Printjobsettings(Blob)

Categories

HOME
android
fabricjs
phpword
delphi-7
merge
xbee
big-o
pyqt4
babeljs
android-json
iis-6
frontend
lanczos
recordrtc
alamofire
pybossa
enterprise-architect
bitnami
microsoft-dynamics-nav
jersey-1.0
identity-management
gmm
selinux
visual-glitch
gulp-watch
hta
php-mysqlidb
easeljs
game-theory
jquery-multiselect
android-sharedpreferences
progress-bar
errbot
winpe
volatile
git-squash
apiary.io
dm-script
sessionstorage
protein-database
spring-mvc-test
setup.py
ogc
magento-1.9.3
doc
escpos
apollostack
angular-http
apache-spark-dataset
phpdbg
pom.xml
reportservice2010
dtsearch
vugen
tinymce-3
twilio-click-to-call
openblas
page-replacement
janus
google-photos
rxtx
cvxpy
mapxtreme
omxplayer
tinkerpop3
x-tag
delta
firebase-security
aurora
libav
jparsec
character-replacement
sciruby
xenomai
django-urls
vacuum
haskell-warp
airbrake
mirror
avahi
snoop
ms-access-2000
osc
bcache
gamekit
grouping-sets
rickshaw
universal-image-loader
create.js
ios8-extension
xmltodict
gtm-oauth2
breakout
gpars
flex++
android-icons
cardreader
cascadingdropdown
swfobject
onmousemove
usertype
box2d-iphone
saxparseexception
filemerge
google-floodlight
lr
cuteeditor
delimited-text
office-2007
dot-emacs
isapi-extension
sun
ifilter
pnrp

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App