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

}

Wednesday, 7 January 2015

Model

Ax 2012 : Edit model manifest properties using Axutil
We can edit the model manifest properties like name,version number,description and publisher by using Axutil commands. In this post I'll create a new model and then edit its version number by using Axutil command.

1. Create a new model : In order to create a new model, go to Tools --> Model Management --> select Create model as shown below.


A new Create model form will open and here we can specify model properties. 
Note - I have given version number as 1.0.0.0. We will change this later.


2. Open command prompt: Now an easy way to open the command prompt to execute axutil commands is to navigate to the bin folder of the server and press shift and right click on the folder. A menu will be displayed. From the menu select open command window here:


Now you will see the following screen.


3. View existing models: In order to view the list of all the installed models we need to type the following command : axutil list


4: Edit the property: The syntax of the command used to edit the properties of a model is as following:
axutil edit /model:<modelname> /manifest:PropertyName=Value 


Now we type the command to edit the manifest property "Version" and assign a new version number: 1.100.3205.500
(P.S. --> Property name in the command is case sensitive. In case you type the property name as "version" then it gives an error. Also, we can specify the model Id instead of model name in the command.)




5. Check the updated version number : Now we again list the models to see the updated version number of the model


Refer to the below MSDN link to see the details of the axutil edit command
http://technet.microsoft.com/en-us/library/hh433512.aspx

Mark / Un Mark -

The code should look like:

 
 
To get Un Mark all - custTable_ds.PAMarked(true,custTableLocal,false);
 
In Button Click method - write below code