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!!!

Sunday, January 29, 2012

Dynamics AX Technical Consultant Interview Questions Series II

Hi,
   Hope you have enjoyed my Previous post for Dynamics AX Technical Interview Questions Series I
Please Find some more Technical Questions below :


  1. What’s new in Dynamics AX 2012
  2. OOPs concepts
  3. Definition of AOT elements
  4. Document Management and Print Management
  5. Visual Form & Report designer
  6. Unit test framework
  7. Reverse Engineering tool
  8. Version Control System in AX 2009
  9. Layers & their usage.
  10. Web Services concept
  11. AIF in Dynamics AX 2009
  12. AX 2009 Workflow configuration
  13. Dynamics AX security hierarchy
  14. AOS Load balancer concept/Clustering
  15. Differences Between :-
    1. AX 4.0 & AX 2009
    2. MorphX & Intellimorph
    3. RunBase & RunBaseBatch
    4. element & this
    5. COM & .NET Business Connector
    6. Concurrent user & Named user
    7. Primary key & Foreign key
    8. Construct & New methods
    9. VSS & TFS
    10. Table & View in AOT
    11. Auto design & Generated design in reports
    12. Business connector & External Connector
    13. Refresh(),reread(),research() & executeQuery()
    14. formDataSource.queryRun().query() & formDataSource.query()
    15. Normal, field fixed & related field fixed relations




Enjoy DAX !!!

Thursday, January 26, 2012

How to Create New Role Center in AX 2009


Create new role center in Dynamics Ax 2009

Compiled from Dynamics Ax Developer help for quick reference.
  1. Open Dynamics Ax enterprise portal (default installation is http://servername/sites/DynamcisAx).
  2. Click on Site Action > Create . Choose Web part page (as most Ax role center using this). Complete the page creation.
  3. Open Ax client > AOT > Web > Web menu item > URLs > New URL.
  4. Specify URL Properties by clicking on the elipsis button. Browse Enterprise portal folder and choose the .aspx page created in the step 2.
    If got error go to here.
  5. Set home page property to YES. (If not the page will not be available to be chosen as user profile role center page).
  6. Right click > Import. This will import the page to AOT under web > web files > page definitions.
  7. Locate the new page definition on step 6. Set the page title properties.
  8. Go to Admin > Setup > User profile. Create a new record. Choose the role center column from drop down.
  9. Click view role center button to test.
Enjoy DAX!!!

Sunday, January 22, 2012

Purchase Order using X++

Hi,
In this post we will learn the below using X++ :

 1) How to Create Purchase Order
 2) How to Create Purchase Order Line
 3) How to Post Purchase Order



static void PurchaseOrder(Args _args)
{
PurchTable pt;
PurchLine pline;
NumberSeq ns;
PurchID pid;
PurchFormLetter pl;
;
//Create Purchase Order
ns=NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().NumberSequence);
pt.initValue();
pid=ns.num();
pt.PurchId=pid;
pt.OrderAccount="4202";
pt.initFromVendTable();
pt.insert();


//Create Purchase Line
pline.clear();
pline.PurchId=pid;
pline.ItemId="1109";
pline.createLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);
info("Purchase Order Created Sucessfully");


//Post the PO
pl=PurchFormLetter::construct(DocumentStatus::Invoice);
pl.update(PurchTable::find(sid),sid,SystemDateGet(),PurchUpdate::All,AccountOrder::None,false,true);
info("Posted Sucessfully");
}


Enjoy DAX!!!

Sales Order using X++

Hi,
In this post we will learn the below using X++ :

 1) How to Create Sales Order
 2) How to Create Sales Order Line
 3) How to Post Sales Order


Code :
public static void SalesOrderDemo(Args _s)
{
// Create the Sales Order

SalesTable salesTable;
NumberSeq NumberSeq;
SalesId sid;
SalesLine sl;
SalesFormLetter fl;
;
NumberSeq =NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().numberSequence);
sid=NumberSeq.num();
salesTable.SalesId = sid;
salesTable.initValue();
salesTable.CustAccount = "1101";
salesTable.initFromCustTable();
salesTable.insert();

//Create the Sales Line with the created Sales Order
sl.SalesId=sid;
sl.ItemId="1109";
sl.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);

info("Sales Order Created with Line");

//How to Post the Sales Order Invoice


fl=SalesFormLetter::construct(DocumentStatus::Invoice);
fl.update(SalesTable::find(sid));
info("Sales Order Posted");

}


Enjoy DAX!!!

Friday, January 20, 2012

Common Prefixes in AX 2009

Hi DAXers,

Please see the common prefixes used in AX 2009 :


Prefix Description
Ax Dynamics AX Typed Data Source
Axd Dynamics AX business Document
BOM Bill of Material
COS Cost Accounting
Cust Customer
HRM Human Resources management
Invent Inventory Management
JMG Shop floor management
KM Knowledge Management
Ledger General Ledger
PBA Product Builder
Prod Production
Proj Project
Purch Purchase
Req Requirements
Sales Sales
SMA Service Management
SMM Sales and Marketting Management
Sys Application Framework and development tools
Tax Tax Engine
Vend Vendor
Web Web Framework
WMS Warehouse Management



Tip When creating new elements, make sure to follow the recommended naming conventions.
Any future development and maintenance will be much easier.

Monday, January 16, 2012

Importing Leads into AX 2009

Hi,
   Today we have a discussion of the Procedure to Import Leads into AX 2009 from a XML File :


1.    Basic >Setup > Import > Documents
  • In Documents form:  Name, CRMContacts; Description, CRM Contacts Document Class; Document Class, AxdSysImportLeads.
  • Click “Validate”, close Documents Form

2.    Basic > Setup > Import > Transformations
  • In Transformations form: Name, XmlToContacts; Document Class, CRMContacts;
  • Click “Load”
  • Select file “SysImport.Leads.xsl" from "C:\Program Files\Microsoft Dynamics AX\50\Application\Share\Include" folder.
  • Click “Validate”
  • General Tab, verify that type of transformation is “XSLT”

3.    Basic > Setup >Import > Formats
  • In Formats form:  Name, XmlFormat; Description, Process Xml Files; Extensions, *.xml; Document Class, CRMContacts; Active (checked)
  • Save, then click “Transformations”
  • On the Format transformations form:  Transformation:  XmlToContacts, close the form
  • On the Formats form, click “Validate”
  • The Import form will appear; select the file “Leads.xml”; click OK

Now you can start and complete the import process.  CRM >Periodic > Import > Leads


Note :
       Format of Leads.xml must be as displayed below :

<Leads xmlns="http://schemas.microsoft.com/dynamics/2006/02/documents/SysImportLeads">
  <Lead>
    <LeadID>9999</LeadID>
    <Memo>Fair customer</Memo>
    <Subject>Intersted in our products</Subject>
    <Name>Kuldeep Singh</Name>
    <Address>
      <Name>Work</Name>
      <City>New York</City>
      <CountryRegionId>US</CountryRegionId>
      <County>LOUDOUN</County>
      <Email>help4mcts@gmail.com</Email>
      <Phone>(123) 456-7</Phone>
      <PhoneLocal>09811480042</PhoneLocal>
      <State>VA</State>
      <Street>NE 1st Street</Street>
      <URL>http://blogs.gtechlearn.com</URL>
      <ZipCode>00346</ZipCode>
    </Address>
    <Address>
      <Name>Home</Name>
      <City>Somewhere else</City>
      <CountryRegionId>US</CountryRegionId>
      <County>LOUDOUN</County>
      <Email>Kuldeepsingh_godara@yahoo.co.in</Email>
      <Phone>(123) 765-4</Phone>
      <PhoneLocal>0</PhoneLocal>
      <State>VA</State>
      <Street>666 N 2nd Street</Street>
      <URL>http://dynamicspost.blogspot.com</URL>
      <ZipCode>00346</ZipCode>
    </Address>
    <ContactInfo>
      <CommunicationTypeId>Email</CommunicationTypeId>
      <Email>help4mcts@gmail.com</Email>
    </ContactInfo>
    <ContactInfo>
      <CommunicationTypeId>PrimaryPhone</CommunicationTypeId>
      <Phone>(123) 456-1</Phone>
    </ContactInfo>
  </Lead>
 </Leads>

Enjoy DAX!!!