Archive for the ‘Knowledge base (Development)’ Category

TreeNode::isValidObjectName( ‘Object name’ );

It is impossible to create EDT from X++ using standard AOTAdd. AOTCompile causes Axapta crash and than unstable work. AOTSave method virtually doesn’t save anything.

Solution: Use export/import methods.
Steps:

  1. Find any EDT node using AOT methods.
  2. Use SysTreeNode::CopyNode() to copy node to the new EDT node.
  3. Change properties according to the needs for the new node.
  4. Export new node EDT to temporary folder.
  5. Parse exported file and set USERTYPE property the same as NAME property.
  6. Import changed xpo file.

Override method firstField on a form, and call after super method setFocus of a control which should focused after form is opened. Example:

    public void firstField(int _flags=1)
    {
        ;
        super(_flags);
        MyControlName.setFocus();
    }

Override FormDataSource method executeQuery:

    public void executeQuery()
    {
        SomeTable T = this.cursor();

        select * from T where …;
    }

But be aware that in this case grid will not support sorting and filtering.

Example:
myTable_ds.object( fieldNum( myTable, myField ) ).visible( false );

Use table method orig(). It returns the orig buffer which is the committed version of the record in the database.

Some times we need to create a new unique index or alter existing one, but table may already contain duplicate data for this index and our changes could not be applied until data in table fixed to support uniqueness. We could do it by deleting records in the table but due to huge number of companies in environment it could be time consuming. To save your time you could use following job:

static void Job3(Args _args)
{
    MyTable myTable;
    DataArea da;
    int cnt;
    ;
    ttsbegin;
    while select da
    {
        cnt = 1;
        changecompany(da.Id)
        {
            myTable = null;
            while select forupdate myTable
            {
                cnt++;
                myTable.FieldForUniqueness = int2str( cnt );
                myTable.update();
            }
        }
    }
    ttscommit;
}

Another way to solve this problem is to make following steps:

  1. Try to synchronize your table
  2. You get an error saying that there are duplicates
  3. Rright away you go to Administration > Periodic > SQL Administration form.
  4. Select your table in the list and run Table actions > Check/Synchronize command.
  5. In appeared form enable “Check Allow duplicated’” and run.
  6. You will get a list of conflicting records to kill.

See example below on how implement mandatory fields in dialog:

    boolean             ret;
    FilePath            workFolder;

    Dialog              dlg;
    DialogField         dfWorkFolder;
    FormStringControl   fsc;
    FormGroupControl    fgc;
    ;

    dlg             = new Dialog( "@CDT135" );
    dfWorkFolder    = dlg.addField( typeid( FilePath ), "@CDT136" );
    fgc             = dlg.mainFormGroup();
    fsc             = fgc.controlNum( 1 ); fsc.mandatory( true );

    while( dlg.run() )
    {
        workFolder  = dfWorkFolder.value();

        if( workFolder)
        {
            ret     = true;
            break;
        }

        dlg.doInit();
    }

To write down the record, which have been just created and does not have modifications use data source method ForceWrite. This method can be used to mark the record as it is changed, and thereby making it a candidate for write, regardless of any changes made to the record. It is valid to call the methods after super in formDataSource::Create(). However, it is not valid in formDataSource::initvalue().

To do this you could use next construction:

myTable.( filednum( myTable, myField ) ) = “XXX”;

This is the same as

myTable.myField = “XXX”;

Example:

Field AccountNum from CustTable have id 1. Then statement CustTable.(1) = “4000” – will initialize field AccountNum with value “4000”.

You could also use this feature while working with record of type Common.

Example:

    Common      common;
    CustTable    custTable;
    ;
    select custTable where custTable.AccountNum == "4000";
    common = custTable;
    info( common.( fieldnum( custTable, Name ) ) );

The output of running this code will be the info log with a message “Light and Design”, Where “Light and Design” – name of the customer with id “4000″.

Advertorial
Interact and Engage
Follow AxaptaTraining on Twitter
Google Translate