Thursday, 7 July 2016

Print No.of Copies for a SSRS report

public static void main(Args _args)
{
    SrsReportRunController controller = new SrsReportRunController();
    SRSPrintDestinationSettings printSettings;

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

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

    // set printer as the destination
    printSettings.printMediumType(SRSPrintMediumType::Printer);
    printSettings.printerName = "My Printer"; // specify your printer name 
    printSettings.printLandscape(true); // print in landscape orientation
    printSettings.numberOfCopies(2);    // print 2 copies
    printSettings.setPaperTray(1); // print to paper tray with index = 1 
          
    printSettings.collate(true);          // collate printed copies

    // suppress the parameter dialog to send directly to printer
    controller.parmShowDialog(false);

    // start operation
    controller.startOperation();
}


http://www.andesoft.net/how-to-overwrite-print-managment-on-a-ssrs-report-on-dynamics-ax-2012/

Print no. of copies separaterly using x++ code in SSRS

Add method for Controller for separate copy of reports.
protected void dialogShow()
{
    SysOperationDialog sysOperationDialog;
    FormRun formRun;

    if (useReportViewerForm)
    {
        dialog.run();
        this.dialogPostRun();

        sysOperationDialog = dialog as SysOperationDialog;
        formRun = sysOperationDialog.formRun();
        formRun.detach();
    }
    else
    {
        super();
    }
}
Add method for Controller for separate copy of reports.
protected void dialogClose()
{
    if(!useReportViewerForm)
    {
        super();
    }
}
class CartonLabelController extends SrsReportRunController
{
    container       printerSettings;
    SRSPrintDestinationSettings printDestinationSettings;
}

protected void prePromptModifyContract()
{
    CartonLabelContract contract;
    PurchParmTable      purchParmTable;

    if(this.parmArgs() && this.parmArgs().record())
    {
        contract = this.parmReportContract().parmRdpContract() as CartonLabelContract;
        purchParmTable = this.parmArgs().record();
        contract.parmPurchParmTable(purchParmTable.parmId);
        contract.parmTableRefId(purchParmTable.TableRefId);
    }
}

public void setPrinterSettings(container _settings)
{
    printerSettings = _settings;

    printDestinationSettings = new SRSPrintDestinationSettings(_settings);

    if (conlen(printerSettings) > 0)
    {
        printDestinationSettings.unpack(printerSettings);
    }
}
public boolean showQueryValues(str parameterName)
{
    return false;
}

public static void main(Args args)
{
    CartonLabelController   cartonLabelController;
    PurchParmTable          purchParmTable;

    cartonLabelController = new CartonLabelController();

    purchParmTable = args.record() as PurchParmTable;

    cartonLabelController.parmArgs(args);

    cartonLabelController.parmReportName(ssrsReportStr(CartonLabelReport,Report));
    cartonLabelController.parmShowDialog(false);
    cartonLabelController.parmDialogCaption("@CIT132");
    cartonLabelController.startOperation();
}

Button Click Method to run the two reports synchronously.

void clicked()
{
    args args = new Args();
    CartonLabelController       cartonLabelController;
    ItemLabelController         itemLabelController;
    container                   printSettingsLoc;
    SecurityRights              sr;
    int                         i;
    ;

    sr = SecurityRights::construct();
    super();

    args.record(PurchParmTable);
    args.parm(PurchParmTable.ParmId);
    for(i=0;i<PurchParmLine.CartonLabels;i++)
    {
        if(PrintCartonLabels.value() == NoYes::Yes  && Global::hasMenuItemAccess(menuitemOutputStr(CartonLabels),MenuItemType::Output))
        {

            cartonLabelController  = new cartonLabelController();

            cartonLabelController.parmArgs(args);

            cartonLabelController.parmReportName(ssrsReportStr(CartonLabelReport,Report));
            cartonLabelController.parmDialogCaption("@CIT132");
            cartonLabelController.parmShowDialog(false);

            if(PurchParmTable.CartonLabelPrintSettings)
            {
                printSettingsLoc = PurchParmTable.CartonLabelPrintSettings;
                cartonLabelController.setPrinterSettings(printSettingsLoc);
            }

            cartonLabelController.parmReportContract().parmPrintSettings().printMediumType(conPeek(printSettingsLoc,3));
            cartonLabelController.parmReportContract().parmPrintSettings().overwriteFile(true);
            cartonLabelController.parmReportContract().parmPrintSettings().fileFormat(conPeek(printSettingsLoc,18));
            cartonLabelController.parmReportContract().parmPrintSettings().fileName(conPeek(printSettingsLoc,20));
            cartonLabelController.parmExecutionMode(SysOperationExecutionMode::Synchronous);
            cartonLabelController.startOperation();
        }
    }
    for(i=0;i<PurchParmLine.ItemLabels;i++)// Loop to run no.of reports based on the field.
    {
        if(PrintItemLabels.value() == NoYes::Yes && Global::hasMenuItemAccess(menuitemOutputStr(ItemLabels),MenuItemType::Output))
        {
            ItemLabelController  = new ItemLabelController();

            ItemLabelController.parmArgs(args);
            ItemLabelController.parmReportName(ssrsReportStr(ItemLabelReport,Report));
            ItemLabelController.parmDialogCaption("@CIT130");
            ItemLabelController.parmShowDialog(false);
            if(PurchParmTable.ItemLabelPrintSettings)
            {
                printSettingsLoc = PurchParmTable.ItemLabelPrintSettings;
                ItemLabelController.setPrinterSettings(printSettingsLoc);
            }
            ItemLabelController.parmReportContract().parmPrintSettings().printMediumType(conPeek(printSettingsLoc,3));
            ItemLabelController.parmReportContract().parmPrintSettings().overwriteFile(true);
            ItemLabelController.parmReportContract().parmPrintSettings().fileName(conPeek(printSettingsLoc,20));
            ItemLabelController.parmExecutionMode(SysOperationExecutionMode::Synchronous);// Added this line to open synchronously.
            ItemLabelController.startOperation();
        }
    }
}

Button Click method to set the printer settings

void clicked()
{
    printSettings = new SRSPrintDestinationSettings();

    super();

    if(SrsReportRunUtil::showSettingsDialog(printSettings))
    {
        PurchParmTable.ItemLabelPrintSettings = printSettings.pack();
    }
}

Wednesday, 6 July 2016

Get Price Agreement for Salesline and update net amount based on discount/ discount percent

static void NetAmountwithdiscounts(Args _args)
{
    SalesLine                  salesline;
                       
   PriceDisc_Price             priceDisc_Price    = PriceDisc_Price::construct();
   PriceDisc_LineDisc          priceDisc_LineDisc = PriceDisc_LineDisc::construct();
   InventDim                   inventDim;
   AmountCur                   LineAmount;
    salesline   =   SalesLine::findInventTransId("015331");
   priceDisc_Price.parmModuleType( ModuleInventPurchSales::Sales);
   priceDisc_Price.parmItemId(salesline.ItemId);
   priceDisc_Price.parmInventDim(salesline.inventDim());
   priceDisc_Price.parmUnitID(salesline.SalesUnit);
   priceDisc_Price.parmPriceDate(systemDateGet());
   priceDisc_Price.parmQty(salesline.SalesQty);
   //priceDisc_Price.parmAccountNum(SalesTable::find(salesline.SalesId).CustAccount);
   priceDisc_Price.parmCurrencyCode(salesline.CurrencyCode);
   priceDisc_Price.parmPriceGroupId("");
   priceDisc_LineDisc.parmAccountLineDiscCode();
   priceDisc_LineDisc.parmItemLineDiscCode(InventTableModule::find(salesline.ItemId, ModuleInventPurchSales::Sales).LineDisc);
     priceDisc_LineDisc.findLineDiscAgreement();
   print priceDisc_Price.price();
   print priceDisc_Price.priceUnit();

 
 

 
   print priceDisc_LineDisc.discAmount();   //linedisc
   print priceDisc_LineDisc.discPct(); //LinePercent
   pause;
  /* LineAmount = PriceDisc::price2Amount(priceDisc_Price.price(),
                                            priceDisc_Price.priceUnit(), //1
                                            PriceDisc::discAmount(SalesParameters::find().Disc, priceDisc_LineDisc.discAmount(), 0),//should call this,
                                            1,                   // deliver now
                                            1,
                                            0,
                                            PriceDisc::discPercent(SalesParameters::find().Disc, priceDisc_LineDisc.discPct(), 0),
                                            "USD",
                                             0,
                                           true);
   print LineAmount;
   pause;*/
}

===========================================================
 PriceDiscPolicyCheckPolicy  checkPolicy;
    SalesLine                   salesline = _salesline;
    salesline.ManualEntryChangepolicy = 0;
    salesline.SystemEntryChangePolicy = 0;

    checkPolicy = PriceDiscPolicyCheckPolicy::newFromParm(salesline.PriceDiscResultFields::parmPriceDiscResultFields());
    if(salesline)
    {
        salesline.selectForUpdate(true);
        ttsBegin;
        salesline.salesPurchLine::resetPriceAgreement();
        salesline.setPriceAgreement(salesline.inventDim(), null ,false,null);

        //salesline.LineAmount = salesline.calcLineAmountForced(salesline.SalesQty, checkPolicy);
        salesline.update();
        ttsCommit;
    }
    return salesline;

Wednesday, 29 June 2016

Working with maps

Use edit method to mark/unmark all records

In continuation to my previous post (Edit method - I), I'll now use edit methods to mark all and unmark all the records of a form. It is a very common requirement to have such ability on forms.
In this post we'll use the edit method created in previous post (Edit method - I) and continue to create new buttons on customer details form to mark all and unmark all records.

To achieve this,we'll be doing the following:
1. Create new buttons on customer details form to mark all and unmark all records.
2. Create new functions on customer details form to mark all and unmark all records.

Let's start:

1. Create 2 new buttons on the customer table form, and change their text property to "Mark All" and "Unmark All" respectively. The CustTable form design should look as shown below:

2. Now we create a new function on this form to mark all the records. Let's name this function as PAMarkAll. We traversed through all the records one by one using a while loop and called the edit method for each record to mark it. The code should look like:

In the above code, we have declared a variable of type custTable which will help us to traverse through all the records shown on the form.
Next we initialize it with the first record using
          custTable_ds.getFirst() function.
Then we start the while loop.
Please note the way we have called the edit method. The first parameter of the edit method signifies that the value is changed, the second parameter is the custTable variable which we are using to iterate the records on the form, the third parameter is to signify that value returned  from the edit method needs to be turned on.
After marking the currently selected record we will get the next record using
        custTable_ds.getNext() method.
The above loop will be executed till the next record is found.
At last we used element.redraw() method to redraw the form.

3. In the similar way we create a new function to unmark all the records, the only change is that we need to pass false as the third parameter in the edit method call. The function to unmark all the records should look as below:



4. The functions that we created above should be called when we click the mark all and unmark all buttons. To do this we override the clicked method of both the buttons. The clicked methods should look like:




Now that we are done with the modifications required to mark all/unmark all the records, let's open the customer master form and then play with mark all and unmark all buttons. On clicking mark all button we'll notice that all the records are marked.



On clicking Unmark all button we notice that all the records are unmarked.


So in the post we saw a good example where we can use edit methods in real time situations. In my coming posts, I'll show how we can use combination of edit and display method to achieve some good features to enhance user experience on Dynamics Ax forms.

Tuesday, 28 June 2016

Displaying an image on a form grid in Dynamics AX

Requiement to Get Warning Symbol   in form Grid :

In my case Warning : so changed the display method

Displaying an image on a form grid in Dynamics AX

Sometimes it is useful to display an image in  a data grid on a from to highlight certain records e.g. records with validation errors as in the example below:
















To achieve this requires 2 main steps:

1. Adding a display method on the table/form datasource that returns an ImageRes
 //BP Deviation Documented  
 display ImageRes errorExist()  
 {  
   #resAppl;  
   return this.ErrorLogged ? #ImageError : #ImageBlank2;  
 }  

2. Adding a new field control on the form by right-clicking on the Grid control within the form design and selecting New Control > Window




 

Set the properties of the new control as follows:





Wednesday, 22 June 2016

Reference lookup for Customer delivery address

I have a  requirement to get Customer Delivery Address in my form .

I have Customer field in my table and need to get all the delivery addresses for that customer as lookup to select for the new address field added.

Added a new field - Drag and drop ( sales line - delivery postal address field ).
maintain relation :  Table.DeliveryPostalAddr == LogisticsPostalAddress.Recid.
Add the field to form at required position. 
AutoDeclaration - yes to Reference Group. 
Properties :
data source - Inventlocation
ReferenceField : DeliveryPostalAddr
ReplacementFieldGroup - Location Reference.

Override Lookup reference method 
public Common lookupReference()
{
    CustTable                   custTable;
    DirPartyTable               dirPartyTable;
    DirPartyLocation            dirPartyLocation;
    LogisticsPostalAddress      logisticsPostalAddress;
    SysReferenceTableLookup     sysRefTableLookup;
    Query                       lookupQuery = new Query();
    QueryBuildDataSource        lookupQueryDataSource;

    // Construct the SysRefTableLookup object
    sysRefTableLookup = SysReferenceTableLookup::newParameters(tableNum(LogisticsPostalAddress),ReferenceGroup);

    // Add the field list that will be displayed on the lookup form
   // You can Change/Add more fields in lookup based on your requirement.

    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Address));
    sysRefTableLookup.addLookupfield(fieldNum(LogisticsPostalAddress, Location));

    // Construct the query's data source
    lookupQueryDataSource = lookupQuery.addDataSource(tableNum(LogisticsPostalAddress));

 // To add multiple values in range.
    while select  Location from LogisticsPostalAddress
        join DirPartyLocation
        join dirPartyTable
        join custTable
            where logisticsPostalAddress.Location == dirPartyLocation.Location
                && dirPartyLocation.Party == custTable.Party
                && custTable.Party == DirPartyTable.RecId
                && custTable.AccountNum == InventLocation.citCustAccount
    {
        // Add ranges to the query data source
        lookupQueryDataSource.addRange(fieldNum(LogisticsPostalAddress, Location)).value(queryValue(LogisticsPostalAddress.Location));
    }


    // Pass the query to the lookup object
    sysRefTableLookup.parmQuery(lookupQuery);

    return sysRefTableLookup.performFormLookup();
}


Before writing custom lookup first you have to add reference control in your form and you have to specify some properties as shown in the screen shot below,

http://dynamicsaxcloud.blogspot.in/2015/06/reference-lookup-for-customer-delivery.html




Wednesday, 8 June 2016

X++ passing current selected records in a form for your report

X++ passing current selected records in a form for your report

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report


Pass the DS records to Class or pass the multiple records to class :

http://axhelper.blogspot.in/2012/01/pass-data-source-records-to-class-or.html

https://community.dynamics.com/ax/f/33/t/91411

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report

http://stackoverflow.com/questions/10014177/x-passing-current-selected-records-in-a-form-for-your-report

https://community.dynamics.com/ax/f/33/p/91411/179700#.UT19BFeGPFk