Tuesday, January 31, 2012

Create Alerts in AX using X++

Hi,
   Lets have the below code for Creating Alerts Programmatically using X++.


static void SendAlert(Args _s)
{
EventInbox inbox;
inbox.initValue();
inbox.ShowPopup = NoYes::Yes;
inbox.Subject = "This is the Alert subject";
inbox.Message = "This is the Alert message";
inbox.AlertedFor = "This alert is just information no links are available";
inbox.SendEmail = false;
inbox.UserId = curuserid();
inbox.TypeId = classnum(EventType);


inbox.AlertTableId = tablenum(Address);
inbox.AlertFieldId = fieldnum(Address, Name);
inbox.TypeTrigger = EventTypeTrigger::FieldChanged;
inbox.CompanyId = curext();
inbox.InboxId = EventInbox::nextEventId();
inbox.AlertCreatedDateTime = DateTimeUtil::getSystemDateTime();
inbox.insert();


}



By Default in AX, We have Change Based Alerts & Due Date Alerts but via code we can create custom alerts for RecodeInsert & RecordDelete as well.


See, EventTypeTrigger Base Enum for more details.

Enjoy DAX !!!

How to Copy Sales Quote in AX 2009

Hi,
The default functionality of Microsoft Dynamics Ax 2009 does not allow to copy a quote when a quote's status is either Lost, Sent, Confirmed, or Canceled.

Today I was asked to allow the users to copy a quote when its status is Sent or Lost. 

To copy a quote go to Sales Quotation Details, choose a record and then go to the header level buttons and click Function > CopyFromAll



The following are the steps to accomplish this very quick:



1- Go to the SalesQuotationTable Form > Designs > Design GroupTable> ButtonGroup:ButtonHeader> MenuButton:ButtonHeaderFunction>method>clicked:

You will see the following code:

void  clicked()
{
    ;
    // Set price simulation buttons

    salesQuotationPriceSimHeader.enabled(!salesQuotationTable.isTemplate());

    salesQuotationTableForm.enableFunctionButtons(salesQuotationTable,
                                                  buttonConvert2Customer,
                                                  buttonAlternativeQuotations,
                                                  buttonCopyAllHeader,
                                                  salesQuotationChangeReasonCode);

    smmDocuments.enabled(!salesQuotationTable.isTemplate());
    super();
}

2- Go to the definition of enableFunctionButtons method (right click > Go To Definition. 

Look for the following line of code:


enableCopyAllHeaderButton           = salesQuotationTableType.mayQuotationBeCopied();

   
3- Go to the definition of the salesQuotationTableType.mayQuotationBeCopied() method, and then make the following changes:

ok = (//salesQuotationTable.QuotationStatus   != SalesQuotationStatus::Sent &&
            salesQuotationTable.QuotationStatus != SalesQuotationStatus::Confirmed &&
            //salesQuotationTable.QuotationStatus != SalesQuotationStatus::Lost &&
            salesQuotationTable.QuotationStatus != SalesQuotationStatus::Cancelled);

Comment the lines in green.


Enjoy DAX!!!

ReleaseUpdateScripts Table in AX 2009

Hi,
   In AX 2009 you can use the  ReleaseUpdateScripts table which contains all upgrade scripts to be scheduled for execution during the Data Upgrade process.

Following is the code to check the "garbase" in the ReleaseUpdateScripts table :


static void CheckGarbaseDemo(Args _s)
{
ReleaseUpdateScripts    releaseUpdateScripts;
Counter                 total;
Counter                 invalid;
;
while select ClassID
    from    releaseUpdateScripts
    group by ClassID
{
    total++;
    if (classid2name(releaseUpdateScripts.ClassID) == '')
    {
        info(int2str(releaseUpdateScripts.ClassID));
        invalid++;
    }
}
info(strfmt(@"Garbage Found %1 invalid classIds out of %2", invalid, total));
}

Get the Current Active Company in Dynamics AX.


Hi,

To get the Current Logged In Company you can Use the curExt() function in AX.

Example :

static void curExtExample(Args _arg)
{
str CompanyId;
;

CompanyId = curExt();
Info(CompanyId);
}



You would also get the same result with below code as well.

static void curExtExample(Args _arg)
{
str CompanyId;
;

CompanyId = CompanyInfo::Find().DataAreaId;
Info(CompanyId);
}


Enjoy DAX!!!

Update Labels in Dynamics AX 2009

Hi,

If you are an .aod (axCus.aod) and .ald (axCONen-us.ald) file Test Server to Production Server. Then, after the import you will restart the AOS (in Production Server) and you will found that the labels you created in Test Server will not be there in the Production Server.

To fix the problem you need to go to Production Server and delete the existing axCONen-us.ali file and restart the AOS again on this environment. After this operation your labels will get updated in the Production Server.

Enjoy DAX!!!

Validate Table from X++

Hi,
   From the below code you can easily validate a table field using X++ code.


static server boolean validateTable(common _common)
{
boolean ret = true;
SysDictTable    dictTable;
int fldCnt, i;
fieldId fid;
;


dictTable = new SysDictTable(_common.TableId);
fldcnt = dictTable.fieldCnt();
for(i = 1; i <= fldcnt; i++)
{
fid = dictTable.fieldCnt2Id(i);
ret = ret && _common.validateField(fid);
}
info(strfmt('Validation Result :%1',ret));
return ret;
}


Deploy SSRS Reports using Code in AX 2012


Following code can be used to deploy SSRS reports in Ax 2012.
However make sure that this code runs from the client, and not as CIL (otherwise you will get run time errors)
I can run this below code as a job and works fine.
Plz Note : This code will only work in AX 2012 as in AX 2009/4.0/3.0 there were no SSRSReport Classes.

static void deploySSRSReportDemo(Args _s)
{
SSRSReportManager mgr=new SSRSReportManager();
SSRSReportConceptNode node=new SSRSReportConceptNode();
;
node=TreeNode::findNode(@"\\SSRS Reports\Reports\SalesInvoice");
mgr.deploymentStart();
mgr.deployReport(node);
mgr.deploymentEnd();
}

Enjoy DAX!!!