Total Pageviews

Showing posts with label ax7. Show all posts
Showing posts with label ax7. Show all posts

Thursday, January 30, 2020

D365FO. Dynamics 365 fiance and operation. Get and update contract of batch job on Controller run method. ax 2012

set Batch id in contract if batch isInBatch check is true

in run method we will update the contract and set the batch id.


class BrFunctionalLocationRecordsController extends SysOperationServiceController
{
    protected void new()
    {
        super(classStr(BrFunctionalLocationRecordsService), methodStr(BrFunctionalLocationRecordsService, functionalLocationRecordsService), SysOperationExecutionMode::Synchronous);
    }

 
    public static BrFunctionalLocationRecordsController construct(SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)
    {
        BrFunctionalLocationRecordsController      controller;
        controller = new BrFunctionalLocationRecordsController();
        controller.parmExecutionMode(_executionMode);
        return controller;
    }

 
    public static void main(Args _args)
    {
        BrFunctionalLocationRecordsController controller;
        // to update contract value at main we can initialize contract here.
        //BrFunctionalLocationRecordsContract   brFunctionalLocationRecordsContract;

        controller = BrFunctionalLocationRecordsController::construct();
        //and can set contract values here
        //brFunctionalLocationRecordsContract = controller.getDataContractObject();
        controller.parmArgs(_args);
        controller.startOperation();
    }

 
    public ClassDescription defaultCaption()
    {
        return "@Br:FunctionalLocationRecords";
    }

   
    public void run()
    {
        BrFunctionalLocationRecordsContract brFunctionalLocationRecordsContract;

       //getting batch contract.
        brFunctionalLocationRecordsContract = this.getDataContractObject();
       
        Batch                                   batch;
        if (this.isInBatch())
        {
            //getting batch information;
            batch = this.currentBatch;
            //setting batch id in contract
            brFunctionalLocationRecordsContract.parmBatchHeader(batch.BatchJobId);
        }
        super();
    }

}

Monday, November 4, 2019

Upload Files To Azure BLOB From D365 FO


Uploading attachment file to Microsoft azure storage account blob.

  1.           Goto https://portal.azure.com
  2.             Goto Storage Account
  3. Click on Add 

  4. Fill details and click Review + Create
  5. Click on create. It will deploy the storage account.
  6. Go to newly created storage account go to access key .
    Key 1 and key 2 or connections strings will be used to access this storage account.
  7. Go to container and click Container
  8. Fill the name and click ok.
  9. Now we will create new runnable class in D365FO to upload file to newly created container.
    using Microsoft.WindowsAzure.Storage;
    using Microsoft.WindowsAzure.Storage.Blob;

    class UploadFileToAzureBlob
    {

        public static void main(Args _args)
        {
            DocuRef     docuref;
            /*const str connectionString =  "";*/
            const str containerName = "selflearningcontainer";
            str storageAccountName = "selflearningtest";
            str key = "”;

            System.IO.Stream attachmentStream = null;
            try
            {
    var storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(storageAccountName, key);
    CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
            
                if(storageAccount)
                {
                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
     CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName);
                    blobContainer.CreateIfNotExistsAsync();

                    changecompany('USMF')
                    {
                        SalesId salesId = '001835';
                        SalesTable SalesTable;
                        //SalesTable salesTable = SalesTable::find(salesId);
                        select SalesId from salestable where SalesTable.salesid == '001835';
                
        select firstonly docuref where docuref.RefTableid == salesTable.TableId
                        && docuref.RefRecid == salesTable.RecId;
                    }

                    if(docuref.isValueAttached())
                    {
                        docuValue = docuref.docuValue();

    CloudBlockBlob blockblob =    blobContainer.GetBlockBlobReference("testingblob");
                        if(blockblob && !blockblob.Exists(null, null))
                        {
                            var storageProvider = docuvalue.getStorageProvider();
                            if(storageProvider != null)
                            {
     var docContents = storageProvider.GetFile(docuValue.createLocation());
                                attachmentStream = docContents.Content;

                                if(attachmentStream)
                                {
                                    blockblob.UploadFromStreamAsync(attachmentStream).Wait();

                                    blockBlob.FetchAttributes(null,null,null);
                                    BlobProperties BlobProperties = blockblob.Properties;
                                    if(BlobProperties.Length == attachmentStream.Length)
                                    {
                                        info("file uploaded successfully");
                                    }
                                }

                            }
                        }
                        else
                        {
                            info("file already exists");
                        }
                    }
                }
                else
                {
                    error("unable to connect azure file storage with the provided credentials");
                }
            }
            catch(Exception::Error)
            {
                error("Operation cannot be completed");
            }
            
        }

    }

  10. Now we will run the class 


D365FO and Sharepoint integration issue on dev box: "You are not authorized to connect to 'https://sharepoint.sharepoint.com/

Troubleshooting SharePoint Integration After Upgrading D365FO to Version .42 After upgrading to Dynamics 365 Finance and Operations (D365FO)...