Total Pageviews

Showing posts with label Dynamics ax 2012. Show all posts
Showing posts with label Dynamics ax 2012. Show all posts

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 


Friday, November 24, 2017

Creating a Valid Time State Table/Maintaining ValidTimeState Record


Maintaining Version of table record
Step 1)
Create Table Name: TableA and add fields to tha table

Note : You can change the ValidTimeStateFieldType to any value when the table contains no data. You can change the value to None even if the table contains data.

Step 2) go to table properties and set following properties          

Now Valid to valid from fields are added to your table automatically

Step 3 ) Create index and go to properties and set following properties

At least 3 fields will be added to index valid to, valid form and one other field (like accountNum as shown in table)

Note : You can change the ValidTimeStateMode property from Gap to NoGap only if the table contains no data. You can change from NoGapto Gap even if the table contains data.






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)...