July 10, 2015

Find the AOT report by name

static void FindReportStartsWithName(Args _args)
 {
   UtilIdElements utilId;
 ;
   while select utilId where utilid.recordType == UtilElementType::Report
   && utilId.name like 'Sales*'
   {
     print utilId.name;
   }
   pause;
 }

April 17, 2015

If caller is a form then disable field on the Customform in Ax 2009


You can achieve this, by 2 ways

1. Using form args
2.Using Menuitem

1.Using Form -  Write the code  in form init()

public void init()
{
    super();  
    if(element.args().caller())
    {
         // Cast the caller and make sure it is the right form.
         callerForm = element.args().caller();

         if (callerForm.name() == formstr(CustTable))
         {
            CustomerInterface_AccountNum.allowEdit(false);
     }
  }
}

2.Using Menuitem- Create a menuitem and assign the object as custom form and Write the code  in form run()

public void run()
{
    super();
   if (element.args().menuItemName() == menuitemdisplaystr(InterfaceMenuItemNoFilter))
  {
    InterfaceTab_ds.filter      (fieldnum(InterfaceTab,CustAccount),InterfaceTab_CustAccount.valueStr());
    InterfaceTab_ds.object(fieldnum(InterfaceTab,CustAccount)).allowEdit(false);
}

}

March 27, 2015

X++ Code to get String in new line

static void StringCutter(Args _args)
{
 TextBuffer buffer;
 str a;

 a= "a,b,c,d";

 buffer = new TextBuffer();
 buffer.setText(a);
 while (buffer.nextToken(0, ','))
{
 info (buffer.token())}
}


March 26, 2015

X++ code to print New Line


static void NewLine_Str(Args _args)
{
    TextBuffer t;
    ;
    t = new TextBuffer();
    t.setText("Hai.Welcome");
    while (t.nextToken(false,'.'))
    {
    info(t.token());
    }
}

March 19, 2015

X++ code to get Financial dimension for a purchase order in Ax 2012

static void ShowVendDefaultDimensions(Args _args)
{
    PurchTable  PurchTable;
    PurchLine PurchLine;
    DimensionAttributeValueSet      dimAttrValueSet;
    DimensionAttributeValueSetItem  dimAttrValueSetItem;
    DimensionAttributeValue         dimAttrValue;
    DimensionAttribute              dimAttr;
    Common                          dimensionValueEntity;
    ;

    // Find our supplier
    PurchLine = PurchLine::find('000093');

    // Find the dimension value set that the vendor points to (for specifying the
    // 'default' dimensions). This table is used as a sort of 'header' that the
    // value set items (DimensionAttributeValueSetItem) records belong to.
    dimAttrValueSet = DimensionAttributeValueSet::find(PurchLine.DefaultDimension);

    // Find all of the 'value set items' linked against the 'value set'
    while select dimAttrValueSetItem
        where   dimAttrValueSetItem.DimensionAttributeValueSet   == dimAttrValueSet.RecId
    {
        // Find the dimension 'value' (DimensionAttributeValue) that the set item points to.
        dimAttrValue        =      DimensionAttributeValue::find(dimAttrValueSetItem.DimensionAttributeValue);

        // Find the underlying attribute.
        dimAttr             = DimensionAttribute::find(dimAttrValue.DimensionAttribute);

        // Use the helper class to obtain a reference to the underlying entity (can be anything)
        dimensionValueEntity = DimensionDefaultingControllerBase::findBackingEntityInstance(
            curext(),
            dimAttr,
            dimAttrValue.EntityInstance);

        info(dimAttr.Name + ' ' + dimAttrValue.getValue());
    }
}

X++ code to convert Number to Text

static void numtotxt(Args _args)
{
real i;
str val;
;

i= 3241.20;

val = numeralsToTxt_EN(i);

val = substr(val,5, strlen(val)-4);

info(strFmt("%1",numeralsToTxt(i)));
info(strFmt("%1",numeralsToTxt_EN(i)));
info(strFmt("%1",val));
}

X++ code to mail Report in AX 2012

public void EmailReport(Args _args)
{
    SrsReportRunController controller = new SrsReportRunController();
    SRSPrintDestinationSettings printSettings;
    SrsReportEMailDataContract emailContract;

    // set report name
    controller.parmReportName(ssrsReportStr(CustTransList, Report));

    // create email contract
    emailContract = new SrsReportEMailDataContract();

    // fill in the email contract details
    emailContract.parmAttachmentFileFormat(SRSReportFileFormat::PDF);
    emailContract.parmSubject("Customer Transaction Report");
    emailContract.parmTo("shwethakodli@outlook.com");

    // get print settings from contract
    printSettings = controller.parmReportContract().parmPrintSettings();

    // update print settings with email contract and use pdf format in the attachment
    printSettings.printMediumType(SRSPrintMediumType::Email);
    printSettings.parmEMailContract(emailContract);
    printSettings.fileFormat(SRSReportFileFormat::PDF);

    // suppress the parameter dialog
    controller.parmShowDialog(false);

    // start operation
    controller.startOperation();
    info("Report Mailed");
}