Friday, August 12, 2022

Download an external file from Azure blob storage in D365 FO X++

Hi folks, 

This post will be useful in scenario where an external file is stored in Azure blob storage and users wants to download that external file without having it stored in D365 FO database. 

Requirement:

Recently, I came across a requirement where I had to access the external file from Azure blob storage and then download that external file for the user from D365 FO application although the file doesn't even exist in D365 FO database. 

Solution:

Below is the code snippet of the solution that can be used to download external file for the users.

 class ExternalFileDownload  
 {  
   public static void main(Args _args)  
   {  
     str url;  
     System.Net.HttpWebRequest httpRequest;  
     System.Net.HttpWebResponse httpResponse;  
     CLRObject clro;  
     System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();  
     Browser browser = new Browser();  
     url = "https://[azureblobstorageurloftenant].blob.core.windows.net/temporary-file/%7B81D4B98A-1989-4B13-B056-684FE6AA86C7%7D/CustGroupPackage_340228B4-1D45-4DC9-9931-5C4900457149_DMFPackage.zip?sv=2014-02-14&sr=b&sig=1uHDh1D%2FqDScyDXE8rPA7HfLgTCnleYd0cPp%2FCkmwwg%3D&st=2022-06-14T16%3A14%3A49Z&se=2022-06-14T17%3A19%3A49Z&sp=r";  
     clro = System.Net.WebRequest::Create(url);  
     httpRequest = clro;  
     httpRequest.set_Method("GET");  
     httpRequest.set_KeepAlive(true);  
     httpRequest.set_ContentType("application/json");  
     httpResponse = httpRequest.GetResponse();  
     httpResponse.GetResponseStream().CopyTo(memoryStream);  
     FileUploadTemporaryStorageResult result = File::SendFileToTempStore_GetResult(memoryStream, "Sample");  
     browser.navigate(result.getDownloadUrl(), true);  
     memoryStream.Close();  
     httpResponse.Close();  
   }  
 }  

Saturday, August 6, 2022

Auto submission of workflow X++

Hi folks,

In this blog, I am going to explain how to submit workflow automatically for approval without user interaction in D365 FO.

Requirement:

I got a requirement where in Vendor master data workflow was required to be submitted automatically for approval because Vendors were created through integration and not manually by D365 FO users.

As part of business process, vendor workflow approval process was configured and implemented for finance key users in D365 FO.

Solution:

As soon as Vendors are created through integration, submit workflow action is triggered by applying the below logic. 

 class AutoWorkflowSubmit  
 {  
   public static void main(Args args)  
   {  
     //Get the VendTable RecId for the vendor to submit the workflow  
     RecId recId;  
     try  
     {  
       ttsbegin;  
       //Pass the recId of VendTable in Workflow class that is responsible to trigger the workflow submit action  
       //Activate the workflow  
       Workflow::activateFromWorkflowType(workFlowTypeStr(VendTableChangeProposalWorkflow), recId, "@AccountsPayable:VendChangeProposalSubmit_SubmittedMessage", NoYes::No);  
       //Pass the recId of VendTable in VendTable class that is responsible to update the workflow status as Submitted  
       VendTable::updateWorkflowState(recId,VendTableChangeProposalWorkflowState::Submitted);  
       ttscommit;  
     }  
     catch(exception::Error)  
     {  
       throw Error("Not submitted");  
     }  
   }  
 }  

Enable and Disable Vendor invoice button on PO list and details page X++

Hi folks, This blog will be useful where vendor invoice process is required to be controlled based on certain conditions. Requirements: Proc...