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");
}

RecordInsertList - Example

static void RecordInsertList_example(Args _args)
{
RecordInsertList recordins;
CustTable cust;
recordins=new RecordInsertList(tablenum(CustTable));
cust.AccountNum='13134';
cust.CustGroup='80';
cust.AccountNum = '12345';
cust.CustGroup = '80';
recordins.add(cust);
recordins.insertDatabase();
info(strfmt("Record inserted"));
}

X++ code to send mail using outlook

static void sendEmailThroughOutlook(Args args)
{
 SmmOutlookEMail smmOutlookEMail = new SmmOutlookEMail();
 Object smmSendEmail;
 ;

 args = new Args();
 args.name(formstr(smmSendEmail));
 args.caller(smmOutlookEMail);
 smmSendEmail = classfactory.formRunClass(args);
 if (smmSendEmail)
 {
 smmSendEmail.init();
 smmSendEmail.setEmailTos("Test123@gmail.com");
 smmSendEmail.setEmailSubject("Test");
 smmSendEmail.run();
 smmSendEmail.refreshControl();
 smmSendEmail.wait();
}
info("done");
}