Search This Blog

Showing posts with label AX. Show all posts
Showing posts with label AX. Show all posts

Friday, August 5, 2022

How to connect Postman with Dynamics 365 Finance and Operation

Connect postman with Dynamics 365 finance and operation


Azure application registration

First we need to register application on the azure portal Go to portal.azure.com and click on the respective subscription. in the Search bar type application registration and click on new application registration




















Specify the below detail as per your requirement 












































Please make a copy of the client id and Tenant id because we will use it further. Click on the Add a certificate or secret 

















Please make a copy of the client secret id and secret value. you will not be able to see the client secret value after closing the dialog. 

Add user in F&O

In the finance and Operation , Navigate to the System administration --> Setup --> Azure active directory application and create the record as per below. Client id should be used over here. 




















Setting in Postman 

First we need to get the token and after we will be using this token to do operation with F&O.

To do the setup in the postman, we need the below values 

   
Key Value
client_id     Application id copied from Azure portal
grant_type     client_credentials
Scope     F&OHomepageURL/.default
client_secret     secret id copied from azure portal
Resource         F&O Home page URL

As per below 






















You will receive the access_token by running above script and you can copy that token or can use environment variable in the postman to store the access_token
as per below 




























TTo test that everything is working fine or not. you can use the token generated above and can get the few customer record as per below



Monday, August 1, 2022

Create lookup method using x++ in Dynamics 365 FO

 void lookup(FormStringControl _control)

    {

        SysTableLookup  tableLookup = SysTableLookup::newParameters(tableNum(EntAssetObjectTable), _control);


        Query                   query           = new Query();

        QueryBuildDataSource    qbdsAssetTable  = query.addDataSource(tableNum(EntAssetObjectTable));


        tableLookup.parmQuery(query);

        tableLookup.addLookupfield(fieldNum(EntAssetObjectTable, SerialID));

        tableLookup.addLookupfield(fieldNum(EntAssetObjectTable, ObjectID));

        tableLookup.addLookupfield(fieldNum(EntAssetObjectTable, Name));        

    

        tableLookup.performFormLookup();

    }

Friday, July 1, 2022

How to download file from Azure Blob using x++ in D365 FO

Create the storage account on the azure as per below and copy the keys to connect to this storage account. 


Create a container inside this storage account named with dynamicsfocontainer. We can upload the files from our local directory. To download the files from blob container we can use the below code in the x++. Below is the runnable class that I have developed. 

You can use the exception as per your requirement and loop as well. 


using Microsoft.WindowsAzure.Storage;

using Microsoft.WindowsAzure.Storage.Blob;

 

internal final class CreateReadWriteBlobStorage

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

    public static void main(Args _args)

    {

        CloudStorageAccount  storageAccount;

        CloudBlobContainer   blobContainer;

        CloudBlobClient      blobClient;

 

        storageAccount = CloudStorageAccount::Parse("DefaultEndpointsProtocol=https;AccountName=dynamicsfinanceoperation;AccountKey=I1IFZ7bdzX61466bAxbNChJVN3PbtUgPfNH5WbXbnc8sTIXS/ffZmN0EDo+zbS+AStn3n0Pw==;EndpointSuffix=core.windows.net");

        blobClient = storageAccount.CreateCloudBlobClient();

       

        blobContainer = blobClient.GetContainerReference("dynamicsfocontainer");

 

        System.Collections.IEnumerable listEnumerable =  blobContainer.ListBlobs(null,true,0,null,null);

        System.Collections.IEnumerator listEnumerator = listEnumerable.GetEnumerator();

       

        while (listEnumerator.MoveNext())

        {

            IListBlobItem item = listEnumerator.Current;

 

            if (item is CloudBlockBlob)

            {

                CloudBlockBlob  blockBlob = item;

                System.IO.FileStream  localFile = System.IO.File::Create(@"C:\Temp\Blob\" + blockBlob.Name);

                blockBlob.DownloadToStreamAsync(localFile);

                Info(strFmt("%1",blockBlob.Name));

            }          

        }

    }

}


Thursday, May 26, 2022

How to calculate the GST amount using x++

 static void Job236(Args _args)

{

    TmpTaxDocument                  tmpTax;

    SalesCalcTax                    salesCalcTax;   

    SalesTotals                     salesTotals1;

    ITaxableDocument                taxableDocument;

    ITaxDocumentComponentLineEnumerator lineEnumerator;

    ITaxDocument                    taxDocumentObject;

    real                            taxTotalGTE,taxtotal,SGST,CGST,IGST;

    ITaxDocumentMeasure             taxMeasure;

    ITaxDocumentMeasureEnumerator   taxMeasureEnumerator;

    ITaxDocumentMeasureValue        partyTaxMeasureValue;

    int                             i;

    SalesLine                       salesLine;

    ITaxDocumentLine                taxDocumentLine;


    salestotals1 = SalesTotals::construct(SalesTable::find("SO-2021-122436"));

    

    

    taxableDocument = TaxableDocumentObject::construct(salestotals1.parmTaxableDocumentDescriptor());

    taxDocumentObject = TaxBusinessService::calculateTax(taxableDocument);

    salesLine = SalesLine::findInventTransId("40016597686");

    if (taxDocumentObject)

    {

        taxTotalGTE = taxDocumentObject.getTotalTax().amountTransactionCurrency();


        // Calculation of Tax amount for Tax type GST and Tax component SGST

        //lineEnumerator = taxDocumentObject.componentLines('GST','SGST');

        taxDocumentline = taxDocumentObject.findLineByOrig(salesLine.TableId,SalesLine.RecId);

        lineEnumerator = taxDocumentline.componentLines("GST","SGST");

        while (lineEnumerator.moveNext())

        {

            taxMeasure = lineEnumerator.current().getMeasure("Rate");

            info(strFmt("SGST Rate %1",taxMeasure.value().value()));

            taxMeasure = lineEnumerator.current().getMeasure("Tax Amount");

            info(strFmt("SGST Rate %1",taxMeasure.value().value()));            

            lineEnumerator.current().

           

        }

        

        lineEnumerator = taxDocumentline.componentLines("GST","CGST");

        while (lineEnumerator.moveNext())

        {

            taxMeasure = lineEnumerator.current().getMeasure("Rate");

            info(strFmt("CGST Rate %1",taxMeasure.value().value()));

            taxMeasure = lineEnumerator.current().getMeasure("Tax Amount");

            info(strFmt("CGST Rate %1",taxMeasure.value().value()));            

           

        }

        

        lineEnumerator = taxDocumentline.componentLines("GST","IGST");

        while (lineEnumerator.moveNext())

        {

            taxMeasure = lineEnumerator.current().getMeasure("Rate");

            info(strFmt("IGST Rate %1",taxMeasure.value().value()));

            taxMeasure = lineEnumerator.current().getMeasure("Tax Amount");

            info(strFmt("IGST Rate %1",taxMeasure.value().value()));            

           

        }

        

        

        

       /* while (lineEnumerator.moveNext())

        {

            taxMeasureEnumerator = lineEnumerator.current().measures();

            while (taxMeasureEnumerator.moveNext())

            {

                i++;

                if (i == 3)

                {

                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();

                    info(strFmt("SGST = %1",partyTaxMeasureValue.amountTransactionCurrency()));

                    SGST += partyTaxMeasureValue.amountTransactionCurrency();

                    i=0;

                    break;

                }

            }

        }


        // Calculation of Tax amount for Tax type GST and Tax component CGST

        lineEnumerator = taxDocumentObject.componentLines("GST","CGST");

        while (lineEnumerator.moveNext())

        {

            taxMeasureEnumerator = lineEnumerator.current().measures();

            while (taxMeasureEnumerator.moveNext())

            {

                i++;

                if (i == 3)

                {

                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();

                    info(strFmt("CGST = %1",partyTaxMeasureValue.amountTransactionCurrency()));

                    CGST += partyTaxMeasureValue.amountTransactionCurrency();

                    i=0;

                    break;

                }

            }

        }


        // Calculation of Tax amount for Tax type GST and Tax component IGST

        lineEnumerator = taxDocumentObject.componentLines("GST","IGST");

        while (lineEnumerator.moveNext())

        {

            taxMeasureEnumerator = lineEnumerator.current().measures();

            while (taxMeasureEnumerator.moveNext())

            {

                i++;

                if (i == 3)

                {

                    partyTaxMeasureValue = taxMeasureEnumerator.current().value();

                    info(strFmt("IGST = %1",partyTaxMeasureValue.amountTransactionCurrency()));

                    IGST += partyTaxMeasureValue.amountTransactionCurrency();

                    i=0;

                    break;

                }

            }

        }*/

    }

}

Monday, December 14, 2020

How to create CSV file using x++ in ax 2012 R3

Creating a csv file using x++ in AX 2012 R3. To create a csv file as we have different - different classed  can be used.

  • CommaIO - Output will be - "0000168";0;"Corrugated Partition 279*333*242mm BC/F"
  • CommaTextIO - Output will be - "0000168";0;"Corrugated Partition 279*333*242mm BC/F" 
  • ASCIIIO - Mainly used where you are dealing with ASCII values.
  • TextIO - Output will be - 0000168;0;Corrugated Partition 279*333*242mm BC/F


With the CommaIO

static void CreateCSVWithCommaIO(Args _args)
{
    #File
    CommaIo             commaIO;
    FileIOPermission    perm;

    Dialog              dlg;
    DialogField         dialogfield;
    Filename            fileName;    
    InventTable         inventTable;
    container           conFile;
       

    dlg = new Dialog(literalstr("Select file"));
    dialogfield = dlg.addField(extendedTypeStr(FileNameSave), literalstr("File name"));
    dlg.filenameLookupFilter(["csv","*.csv"]);
    dialogfield.value(filename);

    if (dlg.run())
    {
        filename = (dialogfield.value());
    }

    if (fileName)
    {
        
        try
        {
            perm = new FileIOPermission(fileName,#IO_Write);
            perm.assert();
            commaIO = new CommaIo(fileName, #IO_Write);
            commaIO.outFieldDelimiter(";");
            inventTable = InventTable::find("0000168");
            conFile += inventTable.ItemId;
            conFile += inventTable.ItemType;
            conFile += inventTable.NameAlias;
            
            commaIO.writeExp(conFile);
         
        }    
        catch(Exception::Error)
        {
            exceptionTextFallThrough();
        }
        
        CodeAccessPermission::revertAssert();
    }

    
}

Tuesday, November 24, 2020

Error Synchronize database Cannot execute a data definition language command on (). The SQL database has issued an error.

When production database has been copied to the test database or development database then we usually get below type of error during database synchronization after applying model store.










(C)\Classes\Info\add 0
(S)\Classes\xApplication\dbSynchronize 0
(S)\Classes\Application\dbSynchronize 30
(S)\Classes\SysSqlAdminClass\handleSelectedItems 34
(C)\Forms\SysSqlAdmin\Methods\runThroughTablesAndIndexes 42
(C)\Forms\SysSqlAdmin\Designs\DesignList\buttonSynchronize\Methods\Clicked 6
Info Synchronize database SQL error description: [Microsoft][SQL Server Native Client 11.0][SQL Server]There is already an object named 'I_111882RECID' in the database.
Info Synchronize database SQL statement: ALTER TABLE "DBO".TAXGSTREPORTCONFIGURATIONLINECODE_MY ADD CONSTRAINT I_111882RECID PRIMARY KEY CLUSTERED (RECID) WITH (DATA_COMPRESSION = ROW )
Error Synchronize database Cannot execute a data definition language command on  ().
The SQL database has issued an error.


You can try to solve the problem from below approach

  1.  Just try to synchronize the individual table and check if there will be any database synchronization error or not
  2. Check the SQL dictionary table and filter with the table id check if all the id's are proper or not.
  3. There might be a problem that id of the index on this table already exists on the another table. you can query on the database that on which table this index id is present.
  4. Check if there is any data in it or not if there is no data in it then you can try to delete it from SQL and same time try to sync it from AX. it will regenerate it. 
  

Monday, November 9, 2020

Failed to create a session; confirm that the user has the proper privileges to log on to Microsoft dynamics

Some time we get the below error during the database synchronization in AX 2012. 


There could be many solution for this error
  1. Check all the users in AX specially the service account like bc proxy account, AOS account and batch account. 
  2. if the problem still not solve then check your access on SQL database. 
  3. we have workaround as well. Just uncheck the Execute Business operation in CIL and do the database synchronization again.