get filter value from grid

example code :

public void getQueryValue()
{
    QueryBuildRange range;
    int ct, i;

    ct = PMTRoutingTable_ds.queryRun().query().dataSourceTable(tablenum(PMTROutingTable)).rangeCount();

    for (i=1 ; i<=ct; i++)
    {
        range = PMTRoutingTable_ds.queryRun().query().dataSourceTable(tablenum(PMTROutingTable)).range(i);
        info(strfmt('Range Field – %1, Value – %2',range.AOTname(),range.value()));
    }
}

references :
https://jkmsdax2012.wordpress.com/2015/05/05/get-the-ranges-and-values-from-query-dynamicaot-using-x-in-ax-2009/

Advertisements

error : “Target principal name is incorrect” when running SSRS AX 2012 R3

Example of the error :
Capture3

In my case , the issue occurred because outdated *.AXC files (ax configuration files) in report server folder.  error cause is still unknown, my client not provided details on what changes they did in the ax server.

How to solve this issue :

  1. Create New AX Configuration Files, refresh WCF (using Refresh Configuration).

Capture3

  1. Export it to a file and rename it to Microsoft.Dynamics.AX.ReportConfiguration

Capture

  1. then replace the file with new one in folder path C:\Program Files\Microsoft SQL Server\MSRS11.\Reporting Services\ReportServer\binCAPTURE1

Get purchase invoice id from packing slip trans (VendPackingSlipTrans)

static void ExampleJob(Args _args)
{
    VendPackingSlipTrans packingSlipTrans;
    VendInvoicePackingSlipQuantityMatch VendInvoicePackingSlipQuantityMatch;
    vendInvoicetrans vendInvoiceTrans;

    select firstOnly packingSlipTrans where packingSlipTrans.RecId == 5637155083;

    select firstonly vendInvoiceTrans
    join VendInvoicePackingSlipQuantityMatch
        where VendInvoiceTrans.SourceDocumentLine == VendInvoicePackingSlipQuantityMatch.InvoiceSourceDocumentLIne
            && VendInvoicePackingSlipQuantityMatch.PackingSlipSourceDocumentLine == packingSlipTrans.SourceDocumentLine;

    info(VendInvoiceTrans.InvoiceId);

}

credited to : EYO

Create Invoice PO base on Packing Slip/Product Receipt by X++

This code will created pending invoice base on VendPackingSlipJour data and posting that’s pending invoice at the end of code.

PurchFormLetter             purchFormLetter;

    PurchTable                  purchTable;
    PurchLine                   purchLine;

    VendPackingSlipJour         vendPackingSlipJour;
    VendPackingSlipTrans        vendPackingSlipTrans;

    VendInvoiceInfoTable        vendInvoiceInfoTable;
    VendInvoiceInfoLine         vendInvoiceInfoLine;
    VendInvoiceInfoSubTable     vendInvoiceInfoSubTable;
    VendInvoiceInfoSubLine      vendInvoiceInfoSubLine;

    PurchId                     purchId;
    PackingSlipId               packingSlipId;
    ;

    purchId = '9001-PO-16-000745';
    packingSlipId = '9001-PO-16-000745-2';

    ttsBegin;
    purchTable = PurchTable::find(purchId);

    while select vendPackingSlipJour
        where vendPackingSlipJour.PurchId == purchTable.PurchId
        && vendPackingSlipJour.PackingSlipId == packingSlipId
    {

        //Generate Pending Invoice Header
        vendInvoiceInfoTable.clear();
        vendInvoiceInfoTable.initValue();
        vendInvoiceInfoTable.initFromPurchTable(purchTable);

        vendInvoiceInfoTable.DocumentOrigin  = DocumentOrigin::Manual;
        vendInvoiceInfoTable.CurrencyCode = purchTable.CurrencyCode;
        vendInvoiceInfoTable.DeliveryName = purchTable.DeliveryName;
        vendInvoiceInfoTable.Num = "INV-" + vendPackingSlipJour.PackingSlipId; //add invoice number in here
        vendInvoiceInfoTable.PurchName = purchTable.PurchName;
        vendInvoiceInfoTable.VendInvoiceSaveStatus = VendInvoiceSaveStatus::Pending;
        vendInvoiceInfoTable.DocumentDate = systemDateGet();
        vendInvoiceInfoTable.LastMatchVariance = LastMatchVarianceOptions::OK;
        vendInvoiceInfoTable.ParmJobStatus = ParmJobStatus::Waiting;
        vendInvoiceInfoTable.Approved = NoYes::Yes;
        vendInvoiceInfoTable.Approver = DirPersonUser::currentWorker();

        vendInvoiceInfoTable.DefaultDimension = vendInvoiceInfoTable.copyDimension(purchTable.DefaultDimension);

        vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,RemittanceLocation),null,purchTable);
        vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,FixedDueDate),null,purchTable);
        vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,ExchRate),null,purchTable);
        vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,TransDate),null,purchTable);
        vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,PaymMode),null,purchTable);

        vendInvoiceInfoTable.insert();

        //Generate Vend Invoice Info reference
        if(vendInvoiceInfoTable)
        {
            vendInvoiceInfoSubTable.clear();
            vendInvoiceInfoSubTable.initValue();
            vendInvoiceInfoSubTable.defaultRow();

            vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
            vendInvoiceInfoSubTable.OrigPurchId = vendInvoiceInfoTable.PurchId;
            vendInvoiceInfoSubTable.PurchName = vendInvoiceInfoTable.PurchName;
            vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;

            vendInvoiceInfoSubTable.insert();
        }

        //select all packing slip line
        while select vendPackingSlipTrans
            where vendPackingSlipTrans.PackingSlipId == vendPackingSlipJour.PackingSlipId
            && vendPackingSlipTrans.VendPackingSlipJour == vendPackingSlipJour.RecId
        {
            //Generate Pending Invoice Line
            purchLine = vendPackingSlipTrans.purchLine();
            vendInvoiceInfoLine.clear();
            vendInvoiceInfoLine.initValue();
            vendInvoiceInfoLine.defaultRow(null,purchLine);
            vendInvoiceInfoLine.initFromPurchLine(purchLine);

            vendInvoiceInfoLine.DeliveryName = vendInvoiceInfoTable.DeliveryName;
            vendInvoiceInfoLine.ParmId = vendInvoiceInfoTable.ParmId;
            vendInvoiceInfoLine.TableRefId = vendInvoiceInfoTable.TableRefId;
            vendInvoiceInfoLine.currencyCode = vendInvoiceInfoTable.CurrencyCode;
            vendInvoiceInfoLine.LineNum = any2int(purchLine.LineNumber);

            vendInvoiceInfoLine.InvoiceAccount = vendInvoiceInfoTable.InvoiceAccount;
            vendInvoiceInfoLine.InventDimId = vendPackingSlipTrans.InventDimId;
            vendInvoiceInfoLine.OrderAccount  = vendInvoiceInfoTable.OrderAccount;
            vendInvoiceInfoLine.ItemId = vendPackingSlipTrans.ItemId;
            vendInvoiceInfoLine.InventTransId = vendPackingSlipTrans.InventTransId;

            vendInvoiceInfoLine.DocumentOrigin = DocumentOrigin::Manual;

            vendInvoiceInfoLine.ReceiveNow = vendPackingSlipTrans.Qty;
            vendInvoiceInfoLine.RemainBefore = vendPackingSlipTrans.Qty;
            vendInvoiceInfoLine.RemainBeforeInvent = vendPackingSlipTrans.Qty;

            vendInvoiceInfoLine.PurchPrice = purchLine.PurchPrice;
            vendInvoiceInfoLine.InventNow = vendPackingSlipTrans.Qty;
            vendInvoiceInfoLine.LineAmount = (purchLine.LineAmount / purchLine.QtyOrdered) * vendPackingSlipTrans.Qty;

            vendInvoiceInfoLine.DefaultDimension = purchLine.DefaultDimension;

            vendInvoiceInfoLine.insert();

            //Generate Vend Invoice Info reference from packing slip
            if(vendInvoiceInfoLine.RecId)
            {
                vendInvoiceInfoSubLine.clear();
                vendInvoiceInfoSubLine.initValue();
                vendInvoiceInfoSubLine.defaultRow();
                vendInvoiceInfoSubLine.ParmId = vendInvoiceInfoTable.ParmId;
                vendInvoiceInfoSubLine.LineRefRecId = vendInvoiceInfoLine.RecId;
                vendInvoiceInfoSubLine.ReceiveNow = vendPackingSlipTrans.Qty;
                vendInvoiceInfoSubLine.InventNow = vendPackingSlipTrans.Qty;
                vendInvoiceInfoSubLine.JournalRefRecId = vendPackingSlipTrans.RecId;
                vendInvoiceInfoSubLine.JournalRefTableId = vendPackingSlipTrans.TableId;
                vendInvoiceInfoSubLine.DocumentId = vendPackingSlipTrans.PackingSlipId;
                vendInvoiceInfoSubLine.insert();
            }
        }

        //Posting pending invoice invoice
        purchFormLetter = PurchFormLetter_Invoice::newFromSavedInvoice(vendInvoiceInfoTable);
        purchFormLetter.update(vendInvoiceInfoTable.purchTable(),vendInvoiceInfoTable.Num);
    }

    ttsCommit;

    info(strFmt('Purchase Order %1 invoiced',purchTable.PurchId));

Get tax amount through x++

static void TIDgetTax(Args _args)
{
    TaxAmount           tax;
    CustInvoiceTrans    CustInvoiceTrans;
    ;

    CustInvoiceTrans =  CustInvoiceTrans::findRecId(5637155209);
    tax = Tax::calcTaxAmount(CustInvoiceTrans.TaxGroup, CustInvoiceTrans.TaxItemGroup, CustInvoiceTrans.InvoiceDate,
                            CustInvoiceTrans.CurrencyCode, CustInvoiceTrans.LineAmount, TaxModuleType::FreeTxtInvoice);

    info(strfmt('%1', tax));
}

Consuming webservices (SOAP) from AX example code

public static container UserInfoByIDRequest(str _storeName, str _idType, str _idNo, str _extRef,str _username = "",str _password = "")
{
    TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.Summary summary;
    TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.RemittanceClient svcClient;
    TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.UserInfoByIDRequest request;
    TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.UserInfoByIDResponse response;

    CLRObject clrObject;
    System.Exception ex;
    str errorCode, errorMesg;
    container  returnCon;
    boolean    canConnectAPI;
    str        errorCanConnectAPI;

    new InteropPermission(InteropKind::ClrInterop).assert();
    try
    {
        clrObject = CLRInterop::getType("TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.RemittanceClient");
        svcClient = AifUtil::createServiceClient(clrObject);

        request = new TIDIDSSIMPONI.ServiceReferences.TIDIDSSR.UserInfoByIDRequest();

        //if no username or password provided, get from AX
        if(!_username || !_password)
        {
            _username = TIDIDSSimponiWebConsumeMethod::getUserNamePasswordStore(_storeName).IPMS_GaleriUserName;
            _password = TIDIDSSimponiWebConsumeMethod::getUserNamePasswordStore(_storeName).IPMS_GaleriPassword;
        }

        request.set_Username(_username);
        request.set_Password(_password);
        request.set_StoreName(_storeName);
        request.set_IdType(_idType);
        request.set_IdNo(_idNo);
        request.set_ExtRef(_extRef);

        //consuming webservice API
        response = svcClient.GetUserInfoByID(request);
        summary = response.get_Summary();

        //unpack to variable
        errorCode = summary.get_ErrorCode();
        errorMesg = summary.get_ErrorMessage();

        //packing all variable to container and return it
        returnCon += errorCode;
        returnCon += errorMesg;



        //sucess connect to webAPI
        canConnectAPI = true;

    }
    catch(Exception::CLRError)
    {
        ex = CLRInterop::getLastException();
        info(ex.ToString());

        canConnectAPI = false;
        errorCanConnectAPI =ex.ToString();
    }

    return [canConnectAPI, errorCanConnectAPI, returnCon];
}