Showing posts with label Microsoft Dynamics NAV 2016. Show all posts
Showing posts with label Microsoft Dynamics NAV 2016. Show all posts

Tuesday, October 10, 2017

How to display sum value in factbox on base of multiple line selection

How to display sum value in factbox on base of multiple line selection
Typical issue is to show a calculated value in a factbox on base of the currently selected line in a list page or the lines in a subpage. Is it possible to get a calculated value on base of more than one selected line? Let’s check out.
Let’s say we want to display the sum of field “Credit Limit” in the customer list when selecting multiple lines. So first we edit page 9082 “Customer Statistics FactBox”. There we add a global variable SumCredLimit (decimal) to the page, then we add a new line in page with sourceexpr = SumCredLimit.




Now we add a new global function SetSumCredLimit.



Save and close the page. Now we edit page 22 customer list. There we rename page part “Customer Statistics FactBox” to CustStatFbx. That’s needed, so that we can reach the custom functions in page “Customer Statistics FactBox” from page “customer list”.



After that edit the page code (F9). Goto trigger OnAfterGetCurrRecord, there add local variable Cust (record|Customer). Add following code to trigger:



Save and close the page. Now run the Nav windows client and goto customer list.
The result:


Reference: jonthan




Friday, April 21, 2017

Microsoft Dynamics NAV 2016 – Business Chart

Microsoft Dynamics NAV 2016 – Business Chart

👋 Hi all,

    Today i came across with different type of requirement, Sometime you might be show the inventory Location wise in the form of chart.

In this article, I’m going to discuss about Business Charts in detail and how you can create them.
Building Business Charts is one of the ways you can take advantage of the powerful charting capabilities in Dynamics NAV.
WHAT ARE BUSINESS CHARTS?
Business charts are based on Business Chart control add-in which is provided by the Microsoft.Dynamics.Nav.Client.BusinessChart.dll assembly.
As compared to other chart types, Business charts provide advanced functionalities such as:
·         Displaying complex data that is calculated on a page.
·         Allowing end users to filter data and drill down to the details from the chart
·         Allowing dynamic filtering of data
·         Being supported on Dynamics NAV Web client.
BUILDING BUSINESS CHARTS FOR ITEM LIST.
At the end of this blog, you will know how to build a simple Business chart which can be used as a factbox in the Item list page showing location wise Inventory.
This chart updates automatically when you move to any particular line on the item list page [See bellow screenshot].



Location wise Inventory Business Chart:
We need to mainly use Business Chart Buffer table (485) to build the business charts. This table holds chart related values and also has multiple functions pre-defined which can be used to build our chart on a page object.
Following objects are required to build Location wise Inventory Business Chart:
·         A Query to calculate Location wise remaining quantity for all the items
·         A Codeunit to use the above query result and prepare Business Chart Buffer table.
·         A Page to display the chart.
To achieve this follow the steps:
1.       Design a new Query object which shows Location wise remaining quantity for all the items. We will be using the query result as chart data.
a)      Open Dynamics NAV development environment and click on Query and next click on New to design a new query
b)      Specify the query DataItem and columns as shown below:


  c)      Save the query. (ex: ID-50027 and Name-Item Qty. By Location)
        d)      Run the query (50027) to see location wise total quantity of items.


2.       Design a new CodeUnit to populate the Business chart buffer table with the above query result.
a)      In the Dynamics NAV development environment, click on Codeunit and next click on New to design a new Codeunit.
b)      In the codeunit designer, click on View–> Globals–> Functions tab to create a new function in the Codeunit. Enter the function name as GenerateInventoryByLoc and click on Locals button to enter parameters and variables for the function as shown in the below image:



c)       Now in the Codeunit designer you see an new function trigger called GenerateInventoryByLoc. Enter the code as shown in the below image. The in-line comments within the Codeunit explains more about each line of code:




 Save the Codunit (ex: ID-50027 and Name- Items Qty. By Loc. - Chart Mgt

3.       Create a ”Items Qty. By Location Chart” page of CardPart type for displaying the Business Chart.

To create a CardPart page follow thr bellow steps:

Ø  Open the Object Designer from Development Enviornment -> Click on Page Type -> Click New.
Ø  Select on Create blank page and then Click on OK.
Ø  Goto Page Properies and give SourceTable as 27 i.e. Item, PageType as CardPart, ID as per your range, in our demo i used 50027, Name Items Qty. By Location Chart. -> Save the Page.
Ø  Now Design your page -> In our case -> Choose 1st Row as a
Type  as Container, SubType as ContentArea, and Name as Container. In 2nd row
Type as Field, Name as BusinessChart -> Goto properties of this line and give the value for ControlAddIn. [Click on Lookup button in ControlAddIn Value and then select  Microsoft.Dynamics.Nav.Client.BusinessChart]
Ø  Now Save the Page and close this designer.
Ø  See the bellow screenshot of Items Qty. By Location Chart.











4.       Now design the Item List page i.e 31, and add a new factbox that we created earlier Items Qty. By Location Chart.

To achieve this we have to do some changes in Item List, follow the bellow procedures.


Ø  Design the Item List Page from Object designer.
Ø  In FactBoxAre add a new line for Items Qty. By Location Chart, and Map it.
Ø  See the bellow screenshot for creating new factbox for Items Qty. By Location Chart.









Note: How you can Open Related page on Click of ”Business Chart” i’ll show you on next article, Thank You...


Credit goes to Subhidha






Thursday, April 21, 2016

Walkthrough: Implementing New Workflow Events and Responses for Sales Header on Delete Record

Walkthrough: Implementing New Workflow Events and Responses

Introduction

Microsoft Dynamics NAV 2016 Workflows enable you to model real-life business processes like best practices or industry-standard practices. Ensuring a customer’s credit limit has been independently verified or requiring a two-person approval for a significant vendor payment are both examples of these.  Workflow can be thought of as the movement of documents or tasks through a work process. Workflows in Dynamics NAV focus on three main building blocks and almost any workflow process, short or long, is likely to be comprised of steps related to these three blocks.  They are:
  • Approval, approval leaves a work task, item or document in an blocked or unapproved state until approved by a suitable person in your organization
  • Notification, notifications tell users that something has happened and/or that they need to take some kind of action
  • Process automation, process automation means executing a process routine and have the Dynamics NAV system calculate something or perform an action


The workflows in Dynamics NAV are represented by Workflow Events and Responses.  The smallest workflow is the pairing of a single Event and a Response.  Simple workflows could be
  • When a new customer is created, email the sales person responsible for that region to alert them to the new customer
  • When a purchase invoice exceeds $250, email the financial controller to alert them


More complex workflows are built of chains of events and responses.  Examples could be
  • When a Purchase Invoice exceeds $250, put the purchase invoice on hold until it is approved by a manager.
  • When new customers are created, block them until they have had a credit check performed.
  • Once a purchase document has been approved by the accounting manager, automatically post it to the Dynamics NAV system.


Note: in all the examples above, you can see a “when something happens, do something” pattern.  This is the “Event and Response” model and is the simple but effective design behind Dynamics NAV workflows.

Events and Workflow Events

Perhaps confusingly, Dynamics NAV 2016 introduces two new event concepts.  Events and Workflow events.  The two are distinct but often coupled together to build solutions.  Dynamics NAV Events allow you to write code which will be called when an event occurs – this is called subscribing to an event.  An example could be to subscribe to the OnCreate trigger for a table and writing code which will be called whenever a new record is created.
Workflow Events typically use Platform Events as their trigger, but are richer.  Workflow events are registered in the workflow engine and show up in the workflow designer.  Microsoft recommends that Workflow events be written at a higher level of abstraction than Platform Events, for example while OnCreateNewCustomerRecord makes a suitable platform event, a good workflow event could be AfterOverduePaymentIsPosted.



Scenarios

Demo 1 – Create a workflow event
The scenario in this demo script is to define an event based on the OnDelete trigger of the “Sales Header” table and expose that event as a workflow event.  This is done in the C/AL Object Designers.  This task is typically performed by C/AL developers.

Demo 2 – Create a workflow response
The scenario in this demo script is to define a response which send an email to “Sales Manager”.  This is done in the C/AL Object Designers.  This task is typically performed by C/AL developers.

Demo 3 - Enable the workflow & response in the NAV system
The scenario of this part of the demo script is to show managing workflow events & responses from a Dynamics NAV system to build a workflow.  This task is typically performed by super users.

Demo 1 - Create a workflow event
To demonstrate the definition of an event you will need to work in the C/AL editor and Object Designer.  Most of the work is done in the code editor and we will use codeunits for our application objects.
  • Open the Microsoft Dynamics NAV 2016 Development Environment.
  • On the Tools menu, choose Object Designer.
  • From Object Designer, create a new codeunit.
  • Create a method called OnDeleteOrderCode. And Give the method a return value of Code, length 128.
  • And write the code: EXIT(UPPERCASE('OnDeleteOrder'));
  • Create the event itself.  This will be an empty method tied to the "Sales Header" table.
  • To do so, make another global method, called OnDeleteOrder.
  • Open the property window for the method (view->properties) and set the Event property to Susbscriber, EventPublisherObject to Table Sales Header and EventFunction to OnAfterDeleteEvent.
  • From the editor, define a local variable for the OnDeleteOrder function.
  • In locals, create a variable called WorkflowManagment, subtype codeunitWorkflow Management
  • Add the code

MESSAGE('My Delete event is fired.');// Testing purpose
     WorkflowManagement.HandleEvent(OnDeleteOrderCode,Rec);

  • Create another event that will be a subscriber to the Add Events to Workflow Library event.
  • To do so, make another global method, called AddEventToLibrary.
  • Open the property window for the method (view->properties) and set the Event property to Susbscriber, EventPublisherObject to Codeunit ‘Workflow Event Handling” and EventFunction to OnAddEventsToLibrary.
  • Create a text constant to hold the user readable string which describes the workflow event. Select view->Globals->text constants and add a new value OnDeleteTxt and set the value to ‘when a sales order is deleted’.
  • Next, define a local variable in the AddEventToLibrary function for calling the WorkflowEventHandling codeunit.
  •  In locals, define variable WorkflowEventHandling as a codeunit of subtype ‘Workflow Event Handling’.
  • Finally add the code which calls that method.


WorkflowEventHandling.AddEventToLibrary(OnDeleteOrderCode,
DATABASE::"Sales Header",
OndeleteTxt,0,FALSE);
Note: [See the bellow screenshot for better understanding].               





The scenario in this demo script is to define a response which send an email to “Sales Manager”.  Most of the work is done in the code editor and we will use codeunits for our application objects.
Note: you can create another codeunit also but in our Demo I’m going to write in this codeunit only.
  • Now Add one Method “RunSendEmailResponseCode” And set the return Type Code And Length 128.
  • Add Code:

                    EXIT(UPPERCASE('RunSendEmailResponse'));

  • Add Another method AddResponseToLibrary.
  • Add another method EsecuteResponse
  • See the bellow screenshot for details of these two methods property & Code







  • Add another method for sending email to sales header
  • See the bellow screenshot for mail sending code.






                                       
Demo 3 — Enable the workflow event in the NAV system

This part of the demo script shows managing workflow events from a Dynamics NAV system.  An entire workflow is comprised of binding a Workflow Event and a Response together and then enabling it.





Kindly let me know via comments, if you wish any clarification from my side. 
In my next post i will describe how we can create own Integration Event and called it whenever the order is Released.


Popular Posts