This Blog is developed for sharing Dynamics 365 Technical knowledge of my & Shilpa's work experience. Myself Today Dynamics 365 Team Lead in ICS Technology. Started with C++, ORACLE, VB, Java & today well-versed with top Microsoft Technologies Power BI, Power Apps & SQL SERVER. Shilpa, She is a NAV Techno-functional consultant & having 4+ years of experience with certified developer. She is a good exposer of Power BI & Power Apps. Love to hear comments from U 4 my posts
Sunday, May 1, 2016
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.
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.
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.
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 codeunit ‘Workflow 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:
- 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.
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.
Labels: MS Dynamincs NAV
Microsoft Dynamics NAV 2016,
Workflow Events & Response
Location: Hyderabad, Telangana, India
Old Airport Rd, Begumpet, Hyderabad, Telangana, India
Monday, March 21, 2016
Outlook Attachment & Send in NAV 2016 Using Dotnet Variables
Hi All,
2. Attach file.
3. Send attachment.
Solution:
To achieve all requirements follow the given steps:
Step-1: Create a codeunit in my case ID 90001, Name "Outlook Attachment & Send".
Step-2: Open the C/AL Globals and Declare theses Variables [See the Bellow Screenshot].
Name DataType Subtype Length
olapp DotNet Microsoft.Office.Interop.Outlook.ApplicationClass.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
olMail DotNet Microsoft.Office.Interop.Outlook.MailItem.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
OlItemType DotNet Microsoft.Office.Interop.Outlook.OlItemType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
olAttachType DotNet Microsoft.Office.Interop.Outlook.OlAttachmentType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
BodyFormats DotNet Microsoft.Office.Interop.Outlook.OlBodyFormat.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Note: Sets the each DotNet Variables "RunOnClient" property "Yes" [See the Bellow Screenshot].
Step-3: Write the C/AL Code on "OnRun" trigger [See the Bellow Screenshot].
Step-4: Save & Run this Codeunit.
Result: Opened Outlook And Sent Email with Attachments.
Note: If this "olMail.Send;" is commented then only display the outlook application with attachment.
Thanks & Best Wishes
Binesh Singh
(MCP, MS, MCTS)
Today I'm going to describe how you can do the bellow requirements using NAV 2016.
1. Open Outlook Application.2. Attach file.
3. Send attachment.
Solution:
To achieve all requirements follow the given steps:
Step-1: Create a codeunit in my case ID 90001, Name "Outlook Attachment & Send".
Step-2: Open the C/AL Globals and Declare theses Variables [See the Bellow Screenshot].
Name DataType Subtype Length
olapp DotNet Microsoft.Office.Interop.Outlook.ApplicationClass.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
olMail DotNet Microsoft.Office.Interop.Outlook.MailItem.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
OlItemType DotNet Microsoft.Office.Interop.Outlook.OlItemType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
olAttachType DotNet Microsoft.Office.Interop.Outlook.OlAttachmentType.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
BodyFormats DotNet Microsoft.Office.Interop.Outlook.OlBodyFormat.'Microsoft.Office.Interop.Outlook, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Note: Sets the each DotNet Variables "RunOnClient" property "Yes" [See the Bellow Screenshot].
Step-3: Write the C/AL Code on "OnRun" trigger [See the Bellow Screenshot].
Step-4: Save & Run this Codeunit.
Result: Opened Outlook And Sent Email with Attachments.
Note: If this "olMail.Send;" is commented then only display the outlook application with attachment.
Thanks & Best Wishes
Binesh Singh
(MCP, MS, MCTS)
Location: Hyderabad, Telangana, India
Hyderabad, Telangana, India
Subscribe to:
Posts (Atom)
Popular Posts
-
Add a QR Code to a Dynamics NAV 2015/2016 in Report Header Hi All, This article will demonstrate how to add a QR Code to a NAV 2016. ...
-
Hi all, Today i came across a different type of query,where Some customers may not want to use Departments menu available. We need to h...
-
👋 Hi all, SFTP Management using WinSCP Recently I have worked on a Website Integration where the requirement was to upload, download, Re...
-
Hello readers, Today I'm going to continue on file handling in business central SaaS to cover the remaining functions as shown in b...
-
Hello readers, Today I'm going to discuss on file handling in business central SaaS. Already other bloggers have been written for on...
-
DATA MIGRATION IN NAV 2016 FROM NAV 2009 Hi all, Today i came across with different type of requirement, Sometimes we need to move/Cop...
-
New Workflows added in NAV 2017 Hi All, Today i came with amazing article in NAV 2017. First of all, I would like to say t...
-
Add Users in NAV 2016 from SQL Server Hi all, Today i came across with different type of requirement...
-
Walkthrough: Implementing New Workflow Events and Responses Introduction Microsoft Dynamics NAV 2016 Workflows enable you to model rea...
-
Hi all, Today I posted how you can Encode And Decode Text. //<<----------------Encoding Text--------------------->> //----...