Tuesday 17 March 2015

Some Functional learned in tasks

create a PO (Functions->Create Purchase Order, Vendor AAP). Go to the PO, lines, Update Line, Registration. Check the line, enter a S/n at the bottom, click Post all. It should update the inventrans linked to item req with the s/n entered – and it should be reflected on assembly completion form.

Printmanagement - Job

static void CIT_PrintLabelUpdate(Args _args)
{
    PrintMgmtDocInstance                printMgmtDocInstance;
    PrintMgmtSettings                   printMgmtSetting ;
    SRSPrintDestinationSettings         srsPrintSettings = new SRSPrintDestinationSettings();
    CustTable                           custTable;

    ttsBegin;

    while select printMgmtDocInstance
        where PrintMgmtDocInstance.ReferencedTableId == 77
           //&& PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::SalesOrderInvoice
           //&& PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::SalesOrderConfirmation
           && PrintMgmtDocInstance.DocumentType      == PrintMgmtDocumentType::Quotation
   {
        printMgmtSetting = PrintMgmtSettings::find(printMgmtDocInstance.RecId,1,true);

        if (printMgmtSetting.RecId)
        {
            srsPrintSettings.unpack(printMgmtSetting.PrintJobSettings);
            if (srsPrintSettings.printMediumType() == SRSPrintMediumType::Email)
            {
                custTable = CustTable::findRecId(printMgmtDocInstance.ReferencedRecId);

                //info(strFmt("Value: %1",CustTable::findRecId(printMgmtDocInstance.ReferencedRecId).AccountNum));
                //info(srsPrintSettings.emailTo());
                //info(srsPrintSettings.emailSubject());

                if (custTable.languageId() == 'nb-no')
                {
                    //srsPrintSettings.emailSubject("Faktura fra Molde Jarnvareforretning AS");
                    //srsPrintSettings.emailSubject("Ordrebekreftelse fra Molde Jarnvareforretning AS");
                    srsPrintSettings.emailSubject("Tilbud fra Molde Jarnvareforretning AS");
                }
                else
                {
                    info(strFmt("Value: %1",CustTable::findRecId(printMgmtDocInstance.ReferencedRecId).AccountNum));
                    info(srsPrintSettings.emailTo());
                    info(srsPrintSettings.emailSubject());


                    //srsPrintSettings.emailSubject("Invoice from Molde Jarnvareforretning AS");
                    //srsPrintSettings.emailSubject("Order confirmation from Molde Jarnvareforretning AS");
                    srsPrintSettings.emailSubject("Offer from Molde Jarnvareforretning AS");

                    info(srsPrintSettings.emailSubject());
                    info('-------------------------');
                }

                //printMgmtSetting.PrintJobSettings = srsPrintSettings.pack();
                //printMgmtSetting.doUpdate();

                //info(srsPrintSettings.emailSubject());
                //info('-------------------------');
            }
        }
    }

    ttsCommit;
}
===================================================================
 https://community.dynamics.com/ax/f/33/t/127517.aspx

static void OverridePrintMangement(Args _args)
{
PrintMgmtDocInstance printMgmtDocInstance;
PrintMgmtSettings printMgmtSettings;
PrintMgmtReportFormat printMgmtreportFormat;
    CustTable   custtbl;
// other
container printerSetting = conNull();
SRSPrintDestinationSettings printDestinationSetting = new SRSPrintDestinationSettings();
// Populate/Create TargetBuffer(s)
printMgmtDocInstance.DocumentType = PrintMgmtDocumentType::SalesOrderConfirmation;
//printMgmtDocInstance.Name = printMgmtDocInstance_Name;
printMgmtDocInstance.NodeType = PrintMgmtNodeType::CustTable;
printMgmtDocInstance.PrintType = PrintMgmtDocInstanceType::Original;
printMgmtDocInstance.PriorityId = 1;
printMgmtDocInstance.ReferencedRecId = 22565434386;  //Recid of Customer
printMgmtDocInstance.ReferencedTableId = 77; //Table Id of custtable
printMgmtDocInstance.insert();
// just use a new instance of SRSPrintDestinationSettings to serialize an empty container
printDestinationSetting.unpack(printerSetting);
printDestinationSetting.printMediumType(SRSPrintMediumType::Screen);
   
    select * from custtbl where custtbl.RecId   ==  22565434386;
printDestinationSetting.emailTo(custtbl.email());
//printDestinationSetting.emailCc(ccEmailString);
//printDestinationSetting.printerName(printerName);
printerSetting = printDestinationSetting.pack();

printMgmtSettings.clear();
printMgmtSettings.Description = printmgmtdocInstance.Name;
printMgmtSettings.NumberOfCopies = 1;
printMgmtSettings.ParentId = printmgmtdocInstance.RecId;
printMgmtSettings.PrintJobSettings = printerSetting;
printMgmtSettings.PriorityId = printMgmtDocInstance.PriorityId;
printMgmtSettings.ReportFormat = printmgmtreportFormat.RecId;
printMgmtSettings.insert();
    info("job is executed");
}

 

Thursday 12 March 2015

Math Functions

1.  Round()
static void Rounding(Args _args)
{
    real    temp, roundingUp, roundingDown;
    ;
    temp = 3000 / 7;
    roundingUp = roundUp(temp, 1);
    roundingDown = roundDown(temp, 1); 
    info(strFmt("Origin : %1 RoundingUp : %2 RoundingDown : %3", temp, RoundingUp, roundingDown));
}
This function rounds the first real argument to the nearest multiple of the second real argument. So plenty of possibilities, for example

round ( 1.2 , 1) equals 1
round ( 1.2 , 5) equals 0
round ( 6.4 , 5) equals 5
round ( 7.5 , 5) equals 10
round ( 1.2 , 0.5) equals 1
round ( 1.12 , 0.1) equals 1.1

If you don't want to work with the multiples of the second argument and instead just want to specify a number of decimals places to round, you can use decround.
This functions rounds the first real argument to the number of decimals specified (second argument). So for example

decround (1.2 , 0) equals 1
decround (1.23 , 0) equals 1
decround (1.23 , 1) equals 1.2
decround (1.25 , 1) equals 1.3

But the second argument can be negative as well. Like this:

decround (123, -2) equals 100


Now for rounding with a little twist: roundup.

If you want to round a number up to the next real value, you can use roundup. This function is the same as the ceiling function from other environments.
Same format as the previous round functions, needing 2 arguments.
So for example

roundup ( 1.23 , 0.1) give as result 1.3
roundup ( 123 , 5) equals 125
roundup ( 123.23 , 5) equals 125
roundup ( 123.23 , 1) equals 124

If that ain't enough, more rounding functions: rounddown and roundzero.
Rounddown rounds your real value always down to the multiple of your second argument.
While roundzero, as the function name says, rounds towards zero.
The difference you can see in the next example:

rounddown (-9 , 5) equals -10
roundzero (-9 , 5) equals -5 

Wednesday 4 March 2015

Conversions

1. Real to string  - Get with format 

Num2Str(custtransopen.AmountMST,10,2,-1,-1)

10 is the length of the string 
2 is the number of decimals
-1 and -1 are the separators before and for the decimal place

2.  Int to string 
int2str .

3. Date to string 
date2str(custtransopen.DueDate,321,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4)

4. Recid to string and again back to Recid

static void Job24(Args _args)
{
    ReportTitle title,stringrecid;
     RecId   recid;
    CustTransOpen custtransopen;
    CustTransOpen=  CustTransOpen::find(5637230869);
    title =  "@SYS12128" + "."+int642str(custtransopen.RecId);
    stringrecid   =   subStr(title,9,strLen(title)-8);
    recid   =   str2recId(stringrecid);
    info(strFmt("%1",recid));

}