mánudagur, 25. mars 2013

Inventory dimension fields

Dynamics AX 2012 - How to look up inventory dimension fields

EcoResTrackingDimGroupSetupCache::active(inventTable.trackingDimensionGroup()).InventBatchIdFlag;

EcoResProductDimGroupSetupCache::active(inventTable.ProductDimensionGroup())...


fimmtudagur, 20. október 2011

Synchronisation error

Got an error when adding new field to InventTable, user did not have rights to sqldictionary table when adding new field?
The field was added to AOTand  the database table, but further synchronisation in AX gave the classic error
"Cannot execute a data definition language command on (). The SQL database has issued an error. Problems during SQL data dictionary synchronisation. The operation failed. Synchronise failed on n table(s)"
Amended by checking the error further in the AOS event viewer and then removing the field in the database and then synchronise in AOT.


föstudagur, 14. október 2011

CLR error when deleting email attachment file


User was prompted with CLR error when sending PDF email.
The email attachment file could not be deleted after the email was sent.  The file was locked as the mailMessage.Dispose() command was missing.

    //move attachment file to Temp folder
    System.IO.File::Move(p1.fileName(), fileNameforEmail);

    attachementCollection   = mailMessage.get_Attachments();
    attachment              = new System.Net.Mail.Attachment(fileNameforEmail);
    attachementCollection.Add(attachment);

    smtpClient                  = new System.Net.Mail.SmtpClient(smtpServer);
    smtpClient.Send(mailmessage);

    mailMessage.Dispose();

    System.IO.File::Delete(fileNameforEmail);

    CodeAccessPermission::revertAssert();

Find record in grid (similar to F4 in XAL)

User asked for a way to find a record in grid without filtering out other records.

Method FindRecord() used.

A button added to the form.  Following code added to the clicked method of the button:

    searchFields = new dialog("Leitargluggi");
    dlgFldVendAccount = searchFields.addField(typeId(VendAccount));
    searchFields.run();


    vend = dlgFldVendAccount.value();
   
    if(vend > '')
    {
        select firstonly mjt where mjt.JournalId == MPSJournalTrans.JournalId
                   &&    mjt.vendAccount == vend;
        if (mjt.RecId)
        {
            MPSJournalTrans_ds.findRecord(mjt);
        }
    }
 
 

Dynamics AX batch, permission rights

Dynamics AX 2009 - file and email right permissions in batch job.  Files to be read, written and deleted.  Email to be sent.

First step was to give the AOS service user rights to the file folder to be written.

As these were multiple files, permission sets were used.

void importFromWorkstation(MPSWorkstation _tWorkstation)
{
    int               iNumberOfFiles;
    FileName          sFileName,fileNamePerm, inFile;
    InteropPermission interopPerm;
    Set               permissionSet, permSetFiles;
    System.Array      files;
    int               i, j;
    container         fList;
    #File
    ;

    permissionSet = new Set(Types::Class);
    permissionSet.add(new InterOpPermission(InteropKind::ClrInterop));

    CodeAccessPermission::assertMultiple(permissionSet);

    files = System.IO.Directory::GetFiles(_tWorkstation.InDir, "*.ut");
    for( i=0; i<ClrInterop::getAnyTypeForObject(files.get_Length()); i++ )
    {
         fList = conins(fList, conlen(fList)+1, ClrInterop::getAnyTypeForObject(files.GetValue(i)));
     }

    CodeAccessPermission::revertAssert();

    permSetfiles = new Set(Types::Class);

    for(j=1;j<=conlen(fList); j++)
    {
        sFileName = conpeek(fList, j);

        //Read files
        permSetFiles.add(new FileIOPermission(sFileName, #IO_Read));


        //Written files
        fileNamePerm = strrem(sFileName, _tWorkstation.InDir) + 'ut';
        fileNamePerm = _tWorkstation.MarelOut + 'po'+ fileNamePerm;
        permSetFiles.add(new FileIOPermission(fileNamePerm, #io_Write));

        fileNamePerm = strrem(sFileName, _tWorkstation.InDir) + 'ut';
        fileNamePerm = _tWorkstation.MarelOut + 'dilkur' + fileNamePerm;
        permSetFiles.add(new FileIOPermission(fileNamePerm, #io_Write));
    }

    //Email
    permSetFiles.add(new InteropPermission(InteropKind::ComInterop));


    // Sys.Io.File.Delete below
    permSetFiles.add(new InteropPermission(InteropKind::ClrInterop));

    CodeAccessPermission::assertMultiple(permSetFiles);

    for(j=1;j<=conlen(fList); j++)
     {
         sFileName = conpeek(fList, j);
         inFile = sFileName;
         sFileName = strrem(sFileName, _tWorkstation.InDir) + 'ut';


         ttsbegin;

         this.parseFileForMarelPO(sFileName, _tWorkstation);
         this.parseFile(sFileName, _tWorkstation);

         System.IO.File::Delete(inFile);

         ttscommit;
     }
    CodeAccessPermission::revertAssert();
}

miðvikudagur, 12. október 2011

Dynamic range in query for AOS batch report

Had to run a daily report in batch, with data from the day before.

Solved by creating a function in SysQueryRangeUtil, currentSessionYesterdayDate() returning SystemDateGet() - 1.

This function was then entered into the report's range: (currentSessionYesterdayDate())