Running custom X++ scripts in Production

Running custom X++ scripts without any downtime?

In 10.0.25 you can run simple X++ scripts on a production environment without any downtime.

This feature lets you run custom X++ scripts without having to go through Dynamics LCS or suspend your system. Therefore, you can correct minor data inconsistencies without causing any disruptive downtime.

Script details page.

Read more :

What are the differences between addOrderByField and addSortField

With addSortField you can set “only” the records order.

With AddOrderByField you can build some logic because is used the kernel class QueryOrderByField.

So, you can use the follow methods :
– direction
– autoHeader
– autoHeaderDetailLevel
– autoSum
– autoSumDetailLevel
– datasource
– fieldId

You can find some examples on the standard class :

– DimensionProvider Class, getDimensionOrderBysFromQuery method
– InventDimCtrl_Frm_OnHand class, modifyQuery method

How to get Label Id from a text

If you want retrieve the Label ID from a specific text description, here the code.
If are present more Label ID for a specific text, you will have the first.

sysLabelEdit     sysLabelEdit = New sysLabelEdit();
labelid          labelid;
str              text = “Customer account”;
str              specialCharsText;

specialCharsText = SysLabel::searchStringBuildSpecialCharString(text);
specialCharsText = SysLabel::seachStringBuildExactStr(specialCharsText);

labelid = sysLabelEdit.findLabel(“en-us”, specialCharsText);

info ( labelid );

Cascade+Restricted Concept in Ax 2012Ax

Step 1:
Create 3 tables for an example :

Table 1- SheetTable, with Two fields Sheetid and sheetname
Table 2-PartitionTable with three fields sheetid , partitionid and sheetsize
Table 3-SheetPartitionTable with two fields partitionid and Shape 

Step 2:

1) Create a relationship between SheetTable and PartitionTable (Ex:PartitionTable.SheetID==SheetTable.SheetId) 

2) Create a relationship between PartitionTable and SheetPartitionTable(EX:SheetPartitionTable.PartitionID==PartitionTable.PartitionID)

Step 3:

1) Create Cascade DeleteAction between SheetTable and PartitionTable

2) Create Cascade+Restricted DeleteAction between PartitionTable and SheetPartitionTable

Step 4:
Open SheetTable and delete the matched record with PartitionTable.

Automatically the matched record from SheetTable , PartititonTable and SheetPartitionTable will be deleted .

Get the phone number of the Delivery Address in the Purchase Order

static void getphoneNumber(Args _args)
PurchTable purchTable;
LogisticsLocation logisticslocation;
LogisticsPostalAddress logisticsPostalAddress;
select purchTable where purchTable.PurchId==”P000059″;
select logisticslocation where logisticslocation.ParentLocation ==

Validate the Special Characters from the given String in Ax 2012

X++ code to validate the special characters from the given string

static void RemoveSpecialCharacters(Args _args)
{str stringVar1,stringVar2;

//String with special characters and numbers
stringVar1= test!@#$%^&*(){}[]|\+-;,.?/~`12344;

//String without Special characters and  numbers

if(stringVar2!=stringVar1 )
{          throw error(“Enter Valid data”);
{            info(“ok”);

Add contact information for entity

How you can add contact information data to an existing entry in the global address book.

static void createPartyContactInfo(Args _args)
DirPartyTable dirPartyTable = DirPartyTable::findByNum(‪‪”100000″);
DirParty dirParty;
DirPartyContactInfoView dirPartyContactInfoView;

// Edit Global address book
dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), DirPartyType::Organization);

// Create contact info
dirPartyContactInfoView.LocationName =’Office’;
dirPartyContactInfoView.Locator =’+43 1 4654646′;
dirPartyContactInfoView.Type = LogisticsElectronicAddressMethodType::Phone;
dirPartyContactInfoView.IsPrimary = NoYes::Yes;



Create primary address through code

The following lines show an example of how you can create a (primary) address for an existing party in the global address book by x ++ code.

The address will only be marked as primary , if no other primary address exists for this party!

static void createPartyAddress(Args _args)
DirPartyTable dirPartyTable = DirPartyTable::findByNum(“‪‪‪100000”);
DirParty dirParty;
DirPartyPostalAddressView dirPartyPostalAddressView;

// Create instance of dirParty
dirParty = DirParty::constructFromCommon(dirPartyTable, DirUtility::getCurrentDateTime(), dirPartyTable.partyType());

// Create primary address
dirPartyPostalAddressView.LocationName = “Office”;
dirPartyPostalAddressView.City = “Vienna”;
dirPartyPostalAddressView.Street = “Kärtnerring”;
dirPartyPostalAddressView.StreetNumber = “18”;
dirPartyPostalAddressView.CountryRegionId = “AUT”;
dirPartyPostalAddressView.IsPrimary = NoYes::Yes;


Post sales invoice through code

Those, who want to have more control over the data to be posted, should take a look at the parameters of salesFormLetter.update().

static void postSalesInvoice(Args _args)
SalesTable salesTable = SalesTable::find(“000747”);
SalesFormLetter salesFormLetter;

salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);

Post sales order confirmation through code

Those, who want to have more control over the data to be posted, should take a look at the parameters of salesFormLetter.update().

static void postSalesConfirmation(Args _args)
SalesTable salesTable = SalesTable::find(“000747”);
SalesFormLetter salesFormLetter;

salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);