Category Archives: D365 Business Central
How to update the selected line in the Subform on click of an action button in the Mainform in NAV
Introduction: The requirement was such that , the user will select a line in the subform. The subform has fields like the Customer ID, Customer Name, and a field Recieved Crates. On click of the action button in the Main form, a page opens which contains the details of the selected line in the subform like Customer ID and Customer Name also a field Crate recieved(Integer Datatype). User will enter Crate Recieved and click on OK. The number entered in the Crate received will modify in the Recieved crates field in the subform. This blog explains the step wise procedure to achieve the above output. Pre-Requisites: Microsoft Dynamics NAV 2017 Steps: 1. Open the Developement Environment of Microsoft Dynamics NAV and open the Main form(card Page) and create an action button Received Crate and write the below code. Here, “Crate Lines” is the Page control (subform), Here a call is made to CallLinesfromCard function with Parameter CratesLine. CallLinesfromCard is a global function made in “Crate Lines”Subform. 2. In the function CallLinesfromCard in the subform. Below is the code. Here ReceiveCrate is a page. Its the page that open on click of the action button. A function is called CrateReceivedFromCust with parameter CrateLinesTable. 3. A global function is made CrateReceivedfromCust in the page ReceiveCrate. Here global fields variables are made CustomerID,CustomerName,NoOfcratesShipped. Theses fields are autopopulated with values from the selected line. A field Crates Received is also created where the user will enter data. 4. OnQueryClosePage of Receive Page, below code is written to modify the Record of the Subform. 5. Set the property RefreshOnactive to yes on the Subform and Mainform.
Share Story :
How to restrict an action button based on time in Microsoft Dynamics NAV
Introduction: Scenario- The requirement was such that on click of the action button a payment transaction is done. The time at which transaction was done is stored in the database. A restriction shouldto be applied to disallow the customer to make payment for the same amount till a certain time E.g. A transaction was done by customer A at 11.40 a.m for amount $100. This customer will be disallowed to make the transaction of the same amount $100 till suppose 5 mins. This time is mins will depend on the client requirement. Pre-requisites: Microsoft Dynamics NAV 2017 Steps: A field is added in the Sales & recivable setup for Time Check in mins. Here, time in minutes is entered say 5 mins. So the payment will be restricted for 5 mins. I’ve written the code on the action button. EFTTransaction.RESET; EFTTransaction.SETRANGE(“Store No.”,’xyz’); EFTTransaction.SETRANGE(“Terminal No.”,’TERM01′); EFTTransaction.SETRANGE(“Sell-to Customer No.”,Rec.”Sell-to Customer No.”); EFTTransaction.SETRANGE(“Account Number”,Rec.”Account Number”); EFTTransaction.SETRANGE(“Transaction Amount”,Rec.”Transaction Amount”); EFTTransaction.SETRANGE(“Transaction Status”,EFTTransaction.”Transaction Status”::Approved); IF EFTTransaction.FINDLAST THEN BEGIN time1:=EFTTransaction.”Transaction Time”; Create Integer variables Hours, Minutes and Seconds and Milliseconds as Decimal variable. Get the transaction time. Time by default is stored in the system in milliseconds. The below code will convert time and store the hour in Hour variable, minutes in Minutes variable and same for seconds. //Code written to convert time to hr min and sec **ST** Milliseconds := time1 – 000000T; //MESSAGE(‘%1 total mili’,Milliseconds); Hours := Milliseconds DIV 1000 DIV 60 DIV 60; Milliseconds -= Hours * 1000 * 60 * 60; Minutes := Milliseconds DIV 1000 DIV 60; Milliseconds -= Minutes * 1000 * 60; Seconds := Milliseconds DIV 1000; Milliseconds -= Seconds * 1000 ; //Code written to convert time to hr min and sec **EN** Get the Time check in mins from Sales & recivable setup and add it up with the Minutes variable. “Rec_Sales&Rec”.GET; Minutes+=”Rec_Sales&Rec”.”Time Check for Credit Card(min”; Now we have till which the transaction should be restricted but the time is stored in Integer variables. Write the below code to convert the integer/decimal variable to time. Milliseconds+=Seconds*1000 +Minutes * 1000 * 60+Hours * 1000 * 60 * 60; //convert time to milliseconds Milliseconds:=Milliseconds/1000; //convert milliseconds to seconds tim := 000000T; tim := tim + (Milliseconds MOD 60) * 1000; // get the seconds Milliseconds := Milliseconds DIV 60; // keep the minutes tim := tim + (Milliseconds MOD 60) * 1000 * 60; // get the minutes Milliseconds := Milliseconds DIV 60; // keep the hours tim := tim + (Milliseconds MOD 60) * 1000 * 60 * 60; // get the hours Here we get our time in time variable. Add the restriction condition. IF (EFTTransaction.”Transaction Date”=TODAY) AND (TIME < tim) THEN ERROR(‘The Transaction for the account number %1 can be only done after %2 mins’,Rec.”Account Number”,”Rec_Sales&Rec”.”Time Check for Credit Card(min”) ELSE BEGIN Submit; “Submit&Settle”; Conclusion : Thus using the above logic time can be converted to Integer variables and then convert Integer variables to time again.
Share Story :
Getting the source code of the .app extension in Microsoft Dynamics Business Central
Objective: This blog demonstrates how to get the source code of the extension app installed in Microsoft Dynamics Business Central. Pre-requisite: Docker Microsoft Dynamics 365 Business Central on Container Nav-Container Helper Module installed in Powershell Demonstration: 1. List the Docker Container: Command: docker ps 2. Entering the Container: Command: Enter-NavContainer <Container Name> 3. List all directories in Container: Command: dir / ls 4. As Extensions are stored in C:\Extensions getting into Extension directory Command: i. cd C:\Extensions ii. dir 5. Exit the Container: Command: exit 6. Copy the .app file inside the container to local path: Command: docker cp <Container Name>:C:\Extensions\<Filename><LocalDirectory> 7. Make a copy & rename the file with .rar as extension 8. Extract the .rar file and explore the ‘src ‘ folder to get the source code in .AL files Conclusion: Thus, in this way the source code is visible and can be used for reference.
Share Story :
How to setup D365 Business Central?
Introduction: The much awaited Dynamics 365 Business Central officially released on 2 April 2018. We are often used to creating virtual machines and setting up Microsoft Dynamics NAV but D365 Business Central doesn’t require a VM, we can set it up on Azure and use it locally. Pre-requisites: Microsoft Azure Licence File Steps: 1. Create a resource group in Microsoft Azure. I have named it navbc. 2. Click on NAVBC resource group and open Azure cloud shell Enter the below command az container create –name MDBC –image “microsoft/dynamics-nav:12.0.21229.0″ –resource-group NAVBC –os-type Windows –cpu 2 –memory 3 –environment-variables ACCEPT_EULA=Y USESSL=N LICENSEFILE=” ” –ip-address public –port 80 443 8080 7049 Here, –name: your container name –resource-group: your resource group name –environment-variables ACCEPT_EULA=Y – mandatory parameter. –ip-address public: mandatory LICENSEFILE=” ” : Here upload your licence to the cloud and then copy the link. –port: list of ports. 8080 is a default value. Use 7049 port number to download symbols whichout which you cannot connect VS code to your container Open your Resource group, the container instace is created click on the instance. This will open the container instance overview page. This will take quite some time approx 15-30 mins get your container instance running. For more information on azure commands click https://docs.microsoft.com/en-us/azure/container-instances/container-instances-quickstarthere 3. To get the container infomation enter the below command az container logs –resource-group navbc –name mdbc 4. Download .vsix file Open your container Instance you will find your IP address. copy it. Copy the link under Files http://<containerIP>:8080/al-0.15.18771.vsix and replace b08.. with the conatiner IP address.This will download your .vsix file. now launch your VSCode and click on Extensions. Install .vsix and AL Language for D365 BC. 5. Publish an Extension Open the launch.json file and replace the server with “http://containerip”. Download symbols using command Ctrl+P Build(ctrl+shift+B) the package and publish it! (Ctrl+ F5). Yay! Now the final step open D365 Business Central. (http://containerip/NAV) This will prompt you for User name and pass word and bang D365 Business Central opens.
Share Story :
Modifying the Primary keys of records in NAV
Introduction: This blog demonstrates how to modify the non-key fields with respect to the key fields. Pre-requisites: NAV 2017 Demonstration: Generally, when modifying the records, the syntax used is Record.FieldName := New_Value; Record.MODIFY(TRUE); In order to do modify the Key fields of the table, we need to know the order in which the keys are assigned. To modify the primary key, the syntax used is Record.RENAME(Key1,Key2,Key3); Where, Key1 corresponds to value that is supposed to be assigned to ‘No.’ field. Key2 corresponds to value that is supposed to be assigned to ‘LineNo.’ field. Key3 corresponds to value that is supposed to be assigned to ‘Leased to Driver No.’ field. Even when the single key field is to be changed, all the key fields should be present in their sequential order. If there is any mismatch in the number of keys, NAV throws the following runtime error. Note: Renaming operation is a costly operation. Creating a New record and Deleting the old record is faster as compared to Rename. In case where the performance is the requirement, the second method is preferred.
Share Story :
How to hide the Delete button in a page in Microsoft Dynamics NAV
Introduction: By default, Delete button is visible on every page in the Home tab but if we do not want the user to delete any record from the page then we need to hide this delete button. This article explains how to hide the Delete button from the Home tab of page. Pre-requisites: Microsoft Dynamics NAV 2017 Steps: 1. Open the Microsoft Dynamics NAV Development Environment, navigate to the List Page where you want hide the delete button and go to properties of the page. 2. Set the DeleteAllowed property to No. 3. Repeat the step 1 and 2 for the Card page 4. Save and Compile the page. 5. We can hide the Edit button by setting InsertAllowed to No and ModifyAllowed Property to No
Share Story :
Workaround to Report.SAVEASPDF in NAV 2018
Objective: In NAV 2017 Emailing the PDF by running the report using Report.SAVEASPDF is now not allowed in NAV 2018. The reason is that temporary server file as not allowed to be saved for some security reasons. Thus this blog demonstrates the workaround solution for this issue. Pre-requisite: NAV 2018 Demonstration: 1. Concept: With respect to NAV 2018, Microsoft says that Emailing the attachments should be done using Streams. Thus, we’ve to convert the PDF generated by running the report into a stream and pass the stream as an attachment (https://community.dynamics.com/nav/f/34/t/270046). Before running the report, the data needs to be passed appropriately to the Report. Report.RUNMODAL method cannot be used as running report requires XML Parameters. For this, we make use of XMLParameters that are sent to the report through either a request page or as XML Text which contains a list of parameters to be passed and then the report is run. 2. Procedure: Step1: Generate the XMLParameters(Text) using the RUNREQUESTPAGE method and copy the results. REQUESTPAGE is used to set the filters prior to running the report. The filters selected are passed to the report in XML format. Value in XMLParameter: Here, Rec.Contract No. is the primary filter to be passed to the report. Step2: Create the Instream and Outstream variables and a temporary table having BLOB field. Create the OutStream variable for the BLOB field of the Temporary Table. Save the data of OutStream variable using Report.SaveAs method. Copy the data of the BLOB field to Instream Step 3: Pass the attachment as a Stream using Instream Note: Perform the Step 1 only if there is any filter to be applied to the report. Conclusion: This workaround is to be used where the Report.SAVEASPDF cannot be used because this method is not allowed in AL.
Share Story :
Error Resolution to “Form.RunModal is not allowed in write transaction” in Microsoft Dynamics NAV
Introduction: Scenario: I had created an action button Print to run a report using REPORT.RUNMODAL, while running this report from the Windows Client an error is thrown as below. Pre-requisites: Microsoft Dynamics NAV 2017 Cause of this error: RUNMODAL stops the transaction and waits for the User interaction. Hence, all users are blocked (who need the table). During a transaction, we are not allowed to open a object with RUNMODAL. Resolution to the error: Use COMMIT statement before you call the REPORT.RUNMODAL. What does COMMIT statement do? When the system enters a C/AL codeunit, it automatically enables write transactions to be performed. When the system exits a C/AL code module, it automatically ends the write transaction by committing the updates made by the C/AL code. This means that if you want the C/AL codeunit to perform a single write transaction, the system automatically handles it for you. However, if you want the C/AL codeunit to perform multiple write transactions, you must use the COMMIT function to end one write transaction before you can start the next. The COMMIT function separates write transactions in a C/AL code module. Example The metasyntax below contains two write transactions. As execution begins, a write transaction is automatically started. Using the COMMIT function, you tell the system that the first write transaction has ended and prepare the system for the second. Once execution has been completed, the system automatically ends the second write transaction. BeginWriteTransactions (C/AL Statements) // Transaction 1 COMMIT (C/AL Statements) // Transaction 2 EndWriteTransactions
Share Story :
Blanket Sales Order Dynamics NAV
Introduction: A blanket sales order represents a sales agreement between the company and a customer. It typically involves one item with multiple shipments at predetermined quantities, price and delivery dates. Scenario: Customer orders 500 units of item that will be delivered 100 units for each week. Steps: 1) In the Search box, enter “blanket Sales orders”, and select the related link. 2) Click on new to create new blanket Sales order. 3) On the General FastTab, in the Sell to Customer No. field, select Customer. 4) Keep the Order Date field blank. When the separate Sales orders are created from the blanket order, the program will set the order date of the Sales order equal to the current date. 5) On the Lines FastTab, in the Type field, select Item. 6) In the No. field, select item. 7) In the quantity field, specify quantity 100. 8) Specify date in Shipment Date field. 9) Create four more lines and specify 100 quantity and shipment date in each line. 10) Now in Qty. to Ship field, keep the quantity of 100 for the first line and delete the quantity to ship in the other four lines. 11) On the Home tab, click Make Order. 12) Click Yes to create an order. 13) You will get message that a Sales order is created from the blanket order. 14) To open the Sales order, select the first line on Blanket order. 15) On the Lines FastTab, point to Line, then to Unposted Lines, and then click Orders. 16) On Home tab of the Sales Lines page, click Show Document. Then the Sales order will appear. Conclusion: By using Blanket Sales Order organization can sell a specified quantity or amount by using multiple Sales orders over time.
Share Story :
Bug fixing for the error ‘The request for path /NAV2018/dev/apps failed with code 422.’
Introduction: Work around to solve the error ‘The request for path /NAV2018/dev/apps failed with code 422. Reason: The value “1473493” can’t be evaluated into type Date’. This is a bug accepted by Microsoft. Thus this blog demonstrate the workaround to the bug until it gets fixed. Pre-requisite: NAV 2018 Demonstration: Converting the text files to AL files from C/AL suing TEXT2AL utility, Thus, InitValue property of the field is set as per the C/AL object but, it throws the following error Workaround to this is either comment out the code and validate the field and add the data. Conclusion: This is a bug and the following method is only a quick fix until a new version is released.
