Microsoft Dynamics

Tales From The Script:

Written by Chandler Hutchison | Oct 2, 2014 5:00:00 AM
 

It is true your Dynamics AX developer has a role to play in the technical aspects of the ERP. For instance, you may be relying on him to create scripts for accomplishing various tasks.

However, if you are a thorough AX user, it may be beneficial to have some basic knowledge on coding scripts. This is especially important if you regularly deal with large masses of data.  By large, we are referring to significant data, perhaps 5,000 or more records.

While you can always use Excel to sort out large data, the software’s performance significantly drops as the size of the data increases. For instance, if you have over 100,000 records to sort out, Excel is likely to “hang” and not produce the output you are anticipating.

To manage large masses of data, coding and running a script will make your work fast. This blog source was written by Murray Fife @murrayfife.

Here is an example on how you can easily code a script to manage large data, without having to call your developer.

Example on How to Code and Run X++ Script

Let’s say that you want to update the Calculation Group of your recently shipped inventory, perhaps because you forgot to load it through DIEF. Here is how you can use X++ script:

i) The first step is to create the script. To do this, click CTRL+D to open up the AOT.
ii) Next, open the Projects explorer by clicking CTRL+SHIFT+P.
iii) Right-mouse-click the Projects folder to reveal a New sub-menu. Click Project from the sub-menu to create a new project.
iv) Name the new project you have created. For your benefit, give it a descriptive name.
v) Next, open the newly-created project by right-mouse-clicking it and selecting Open. The project will be displayed.
vi) Navigate to the header and right-mouse-click to reveal a menu. Select New on the revealed menu and choose the Job
vii) Now, create a variable that points to the table you want to update. In this example, our table is InventTable and the variable is item. Combining these two, we have the following code:

InventTable item;

viii) The next step is to create a loop that will step through every record. To do  this, type:

while select forUpdate item
{
}

ix) Now add your code to find out if there is a record in the table to be updated.  The resulting code will look like this:

if (item)
{
}

x) The final step is to add your code to update the record:

ttsBegin;
item.BOMCalcGroupId = "DEFAULT";
item.update();
ttscommit;

xi) At this point, your code will look like this:

static void Job11(Args _args)
{
InventTable item;
while select forUpdate item
{
if (item)
{
ttsBegin;
item.BOMCalcGroupId = "DEFAULT";
item.update();
ttscommit;
}
}
}

xii) The final step is to run the code. To start, click the green play button on the menu bar.  The script will run and update all  the records for you.

This is how you can easily update your AX data with X++ script.