Monday, 14 December 2020

Export file Azure blob using data entity in d365 f&o

 public void exportFileInAzureBlobUsingEntity()

 {


        #DMF


        SharedServiceUnitFileID fileId;


        DMFDefinitionGroupName definitionGroupName = 'DefinationGroupName'


        try


        {


    DMFEntityName               entityName              = DMFEntity::findFirstByTableId(tableNum(‘TargetEntityName’)).EntityName;


        DMFDefinitionGroupEntity    definitionGroupEntity   = DMFDefinitionGroupEntity::find(definitionGroupName, entityName, true);


        ttsbegin;


        Query                query = new Query(DMFUtil::getDefaultQueryForEntityV3(entityName));


        QueryBuildDataSource qbds = query.dataSourceTable(tableNum(‘TargetEntityName’));


//If need to pass a range below is required             


definitionGroupEntity.resetQuery();


        SysQuery::findOrCreateRange(qbds, fieldNum('TargetEntityName', 'fieldName')).value(queryValue(''));


        SysQuery::findOrCreateRange(qbds, fieldNum('TargetEntityName', 'fieldName')).value(queryValue(''));


        if (definitionGroupEntity) // Update the query range 

        {

            QueryRun    queryRun    = new QueryRun(query);

            container   queryData   = queryRun.pack();

            definitionGroupEntity.QueryData = queryData;


            definitionGroupEntity.update();

        }

        ttscommit;


        DMFEntityExporter exporter = new DMFEntityExporter();


        fileId = exporter.exportToFile(entityName,


                                    definitionGroupName,


                                    '', //Optional: ExecutionID


                                    ‘FileFormat’, //Optional::File Format


                                    #FieldGroupName_AllFields, //Optional field selection


                                    query.pack(),


                                    curExt());

         if (fileId != '')

         {

             str downloadUrl = DMFDataPopulation::getAzureBlobReadUrl(str2Guid(fileId));               

             Filename filename = ‘FileName’

             System.IO.Stream stream = File::UseFileFromURL(downloadUrl);


             //Upload in Azure blob 

             str azureStorageAccount = ‘Azure storage account name’;

             str azureStorageKey = ‘Azure storage account key’;


             Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(azureStorageAccount, azureStorageKey);


             Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);


             var blobcli = storageAccount.CreateCloudBlobClient();


             Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer cont = blobcli.GetContainerReference('Export container folder path Ex: Container/folder);


             CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(fileName);


             cloudBlockBlob.UploadFromStream(stream, null, null, null);


        }

        else

        {

             throw error("");

        }


        }

        catch

        {

            error("");

        }

Monday, 20 August 2018

Monday, 5 February 2018

List page refresh in ax 2012

List page refresh in ax 2012 


After performing some task on the List page. You need to refresh the record. For that, you can find the below code to perform the task.

       //Declaration 
    #Task
    FormRun formRun;
    
    // Get an instance of the calling form.
    formRun = element.args().caller();
    
    // If the caller is a form, refresh that form.
    if(formRun)
    {
        formRun.task(#taskF5);
    }

After completion of your code you can write this code.

Thanks....!

Monday, 6 November 2017

No tree node for \DataDictionary\Tables

No tree node for \DataDictionary\Tables



Getting error while generating source file in DMF.

Solution:

For this error, just re-start the AOS Server.


Thanks

Thursday, 5 October 2017

Import and export of Model in ax 2012


Import and export of Model in ax 2012


Hi all

I have a scenario for moving the model object to one AOS to another AOS. But the AOS is located in the same server.

For this situation, i have know what are the database for this two AOS.

You have to export or import the objects you must take the "Model database" only.

How to Import and Export:

On the Start menu, point to All Programs, point to Administrative Tools, and then click Microsoft Dynamics AX Management Shell.

For Export:

Export-AXModel -Model "USR Model" -File "c:\temp\USR_Model" -Database TestDAX_Model

For Import:

Install-AXModel -File "c:\temp\USR_Model" -Database TestDAX_GST_model

While importing the object the same Model name already exist in the importing AOS i.e., (In two AOS "USR Model" name is exist). You face conflict for this use this command.

Install-AXModel -File "c:\temp\USR_Model" -Database TestDAX_GST_model -createparents -Conflict Push

Importing is done.

Make sure that Restart the AOS, synchronize, compile, full CIL.


Thanks

Wednesday, 26 April 2017

FTP file transfer to another server in ax 2009


FTP file transfer to another server in ax 2009


static void uploadTestFile(Args _args)
{
   System.Object ftpo;
   System.Object ftpResponse;
   System.Net.FtpWebRequest request;
   System.IO.StreamReader reader;
   System.IO.Stream requestStream;
   System.Byte[] bytes;
   System.Net.NetworkCredential credential;
   System.String xmlContent;
   System.Text.Encoding utf8;
   System.Net.FtpWebResponse response;
   ;
   // Read file
   reader = new System.IO.StreamReader("E:\\signed file path\Test.xml");
   utf8 = System.Text.Encoding::get_UTF8();
   bytes = utf8.GetBytes( reader.ReadToEnd() );
   reader.Close();
   // little workaround to get around the casting in .NET
   ftpo = System.Net.WebRequest::Create("ftp:/198.168.64.108:24/Imges/Test.xml");
   request = ftpo;

   credential = new System.Net.NetworkCredential("ananymous","P@ssw0rd");
   request.set_Credentials(credential);
   request.set_ContentLength(bytes.get_Length());
   request.set_Method("STOR");
   // "Bypass" a HTTP Proxy (FTP transfer through a proxy causes an exception)
   // request.set_Proxy( System.Net.GlobalProxySelection::GetEmptyWebProxy() );
   requestStream = request.GetRequestStream();
   requestStream.Write(bytes,0,bytes.get_Length());
   requestStream.Close();

   ftpResponse = request.GetResponse();
   response = ftpResponse;
   info(response.get_StatusDescription());
}

Monday, 24 April 2017

C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin\AX32.exe

C:\Program Files (x86)\Microsoft Dynamics AX\50\Client\Bin\AX32.exe



Hi,

I am getting the following error while run login with different user in ax 2009 Configuration files.






For this resolution:

Add the user( who login you want to access that user)  in user group of your system. Then try to run again login with different your.

Issue resolved for me.