Using #localmacro

Using the option #localmacro can reduce the size and also the visibility of your code.

For example, you create a while select statement and you have to control date range when some value are enable (so not all the time)

You can write this kind of code :

protected void doProcess()
{
    #localmacro.CheckDateDelivery
        (salesTable.DeliveryDate >= fromDate && salesTable.DeliveryDate <= toDate)
    #endmacro

    #localmacro.CheckDateDocument
        (custPackingSlipJour.DeliveryDate >= fromDate && custPackingSlipJour.DeliveryDate <= toDate)
    #endmacro
    ;

    while select salesTable
    where (!validatedOrTransmited   || ((salesTable.MySalesStatus    == MyStatus::Transmission
                                    ||   salesTable.MySalesStatus    == MyStatus::Validation))
    && #CheckDateDelivery)
    &&    (!prepared                ||  (salesTable.MySalesStatus    == MyStatus::Prepare
    && #CheckDateDelivery))
    &&    (!delivered               ||  (salesTable.MySalesStatus    == MyStatus::Delivery))
    exists join firstOnly custPackingSlipJour
    where   custPackingSlipJour.SalesId == salesTable.SalesId
    &&     (!delivered  || #CheckDateDocument)
    {
        // code here.
    }
}
Advertisements

Use of TextIO

There is a little simple example of “How to use the TextIO” classes.

Write

public void writeOnFile(FileName _fileName, str _value)
{
boolean first = true;
container value;
TextIO file;

//add to the end of the file
//file = new AsciiIO(_fileName, #io_append);
//create a new file
file = new AsciiIO(_fileName, #io_write);
file.outFieldDelimiter(";");
value += _value;
file.write(value);
super();
}

Read

private void importFile(FileName _fileName)
{
#define.FIELD_DELIMITER(";")
TextIO file = new TextIO(_fileName, #io_read);
if (!file || file.status() != IO_Status::Ok)
{
throw error("Can't open file"); }
file.inFieldDelimiter(#FIELD_DELIMITER);
line = file.read();
while (conLen(line))
{
// Your code
line = file.read();
}
file = null;
}

Shell execute on batch server

There below the code for simulate a ShellExecute method for the Batch, because, as you have certainly see, we can’t execute the standard WinAPI::execute() method.
I make my example with the FTP command.
server static void shellExecuteFTP(Filename _fileName, str _localFolder)
{
#WinAPI

System.Diagnostics.Process process;
System.Diagnostics.ProcessStartInfo processStartInfo;
;

new InteropPermission(InteropKind::ClrInterop).assert();

process = new System.Diagnostics.Process();

processStartInfo = new System.Diagnostics.ProcessStartInfo();
processStartInfo.set_FileName(@"C:\WINDOWS\System32\ftp.exe");
processStartInfo.set_Arguments(_fileName);
processStartInfo.set_WorkingDirectory(_localFolder);

process.set_StartInfo(processStartInfo);

process.Start();

//process.WaitForExit();
process.Close();
}

Posted in AX5

Object Server 02: Concurrent number of AOS’ for this application exceeds the licensed number.

I receive this error. There below the solution to launch your AOS.
I have next situation: I create a copy of my production database and restore it to my test database. Then I try to start my second test AOS (stopped to allow restore of db):
Object Server 02: Concurrent number of AOS' for this 
application exceeds the licensed number.
Solution:
  • Stop your production AOS
  • Start test AOS
  • Start production AOS again.

Change company

You can use the statement “changeCompany”
But when you want open a new form into another company, it’s a better to choice this peace of code:

boolean promptChangmentOfCompany = false;
appl.setDefaultCompany(_companyId, promptChangmentOfCompany);

Posted in AX5

Show dimension in a new form

Show the dimension of an item in a new form with new table. Your form must contain the datasource InventDim linked to your table with the InventDimId. 
Set the properties of your table like this :
You must add the InventtoryDimensionGroup (copy from SalesTable for example)
Add a new button in the form from the MenuItemDisplay  InventDimParmFixed
After that, in the classDeclaration :
public class FormRun extends ObjectRun()
{
InventDimCtrl_Frm_activeRightClick inventDimFormSetup;
}
Create the following methods:
Object inventDimSetupObject()
{
return inventDimFormSetup;
}
 
void updateDesign(InventDimFormDesignUpdate _mode)
{
InventDimParm inventDimParm;

switch (_mode)
{
case InventDimFormDesignUpdate::Init :
inventDimSetupGrid::initInventDimParmInventTrans(InventDimParm);
if (!inventDimFormSetup)
{
inventDimFormSetup = InventDimCtrl_Frm_activeRightClick::newFromForm(element);
}
inventDimFormSetup.parmDimParmVisibleGrid(inventDimParm);
inventDimFormSetup.formSetControls(true);
break;
}
}
And now, modify your init() method:
public void init()
{
super();
element.updateDesign(InventDimFormDesignUpdate::Init);
}