Skip to content

Michael Heydasch's picture

Notification Messages in Older Versions of Dynamics NAVdeveloper dude - ArcherPoint

As we all know, it's easy to display an informational message to the user with the C/AL keyword MESSAGE. But, how many of you have encountered clients with MESSAGEs built up over time, where the user had to click through five MESSAGEs when entering a sales line, for example?  MESSAGEs are cluttered, intrusive, invasive, modal and require user interaction in order to make them go away. Basically, MESSAGEs are an outdated way to make the user aware of something.

NAV 2017 introduces notifications for the Web Client, an easy, non-intrusive and non-invasive way to display a message to the client via an information bar just below the action pane. Notifications require no interaction from the user to make it go away and can even include an action, like navigate to the customer card.

Dynamics NAV Modeless Notification example
Figure 1 - Modeless notifications in later versions of Dynamics NAV

ArcherPoint’s own Saurav Dhyani published a blog discussing smart notifications in NAV 2017.

Modeless Notification Messages in Dynamics NAV 2017

If you're looking for something like this to replace MESSAGE for the versions of NAV from 2009 RTC to 2016, then this blog entry is for you.  The inspiration for this blog entry was the search for a modeless way of displaying an informational message to the user that requires no interaction.

I'm sure you're familiar with the Notes FactBox, present on most page objects, where users can send notifications to one another. The code shown further below will enable you to generate a new notification and have it displayed immediately (at least in my testing).

The example shown below occurred just after changing a value on the Item Card. To achieve this, a new Subscriber function was created in NAV 2016; the event to which the function subscribed was the OnAfterValidate for a custom field on the Item Card; in the function, code was written to call the custom function CreateNotification.

Using a Note to achieve modeless notification in Dynamics NAV versions 2009 RTC to NAV 2016
Figure 2 - Using a note to achieve modeless notification in versions of Dynamics NAV 2009 RTC to 2016

Dynamics NAV code to Create a new function CreateNotification

Here's how you achieve this in a custom codeunit:

    PROCEDURE CreateNotification@1240060003(_Note@1240060007 : BigText;_Notify@1240060008 : Boolean;_UserID@1240060009 : Text[132];_RecordID@1240060012 : RecordID);

    VAR

      _RecordLink@1240060004 : Record 2000000068;

      _RecRef@1240060011 : RecordRef;

      _char1@1240060000 : Char;

      _char2@1240060001 : Char;

      _is@1240060003 : InStream;

      _NewID@1240060005 : Integer;

      _os@1240060002 : OutStream;

      _TextToWrite@1240060006 : BigText;

      _TextSmall@1240060013 : Text[250];

    BEGIN

      // AP0004 >>

      // code portions courtesy Matt Traxinger - http://mibuso.com/downloads/i-love-nav-enhanced-notes-v2.01

      // first, prepend the BLOB text with the length of the text

      IF _Note.LENGTH <= 255 THEN BEGIN

        _char1 := _Note.LENGTH;

        _TextToWrite.ADDTEXT(FORMAT(_char1));

      END ELSE BEGIN

        _char1 := 128 + (_Note.LENGTH - 256) MOD 128;

        _char2 := 2 + (_Note.LENGTH - 256) DIV 128;

        _TextToWrite.ADDTEXT(FORMAT(_char1) + FORMAT(_char2));

      END;

      // second, append the actual text passed as parameter

      _TextToWrite.ADDTEXT(_Note);

      // third, get the actual user ID passed in as parameter

      IF _UserID <> '' THEN

        IF COPYSTR(_UserID,STRLEN(_UserID)) = ',' THEN

          _UserID := COPYSTR(_UserID,1,STRLEN(_UserID) - 1);

      // fourth, generate a new Record Link rec for the RecordID passed as parameter

      _Note.GETSUBTEXT(_TextSmall,1);

      _RecRef.GET(_RecordID);

      _NewID := _RecRef.ADDLINK(_TextSmall);

      // fifth, write the text (with prepended length) to the Record Link rec

      _RecordLink.GET(_NewID);

      _RecordLink.CALCFIELDS(Note);

      _RecordLink.Note.CREATEOUTSTREAM(_os);

      _TextToWrite.WRITE(_os);

      // sixth and final, set some additional fields and modify the record

      _RecordLink.Type := _RecordLink.Type::Note;

      _RecordLink.Notify := _Notify;

      _RecordLink."To User ID" := _UserID;

      _RecordLink."User ID" := LOWERCASE(_RecordLink."User ID");

      _RecordLink.MODIFY;

      // AP0004 <<

    END;

 

Dynamics NAV code to Call the Function

Here's the code to call the function, located in the custom EventSubscriber function:

      _Item.GET(Rec."No.");

      _RecRef.GETTABLE(_Item);

      _RecID := _RecRef.RECORDID;

      CreateNotification(_bt,TRUE,USERID,_RecID);

Here are the variables for the above code snippet:

      _Item@1240060004 : Record 27;

      _bt@1240060008 : BigText;

      _RecID@1240060003 : RecordID;

      _RecRef@1240060005 : RecordRef;

 

Thanks to Matt Traxinger for his community contribution of Enhanced Notes. His code formed the basis for this modification (and saved a lot of research).

A quick Google search revealed other, similar pages referencing this topic:

https://community.dynamics.com/nav/f/34/t/198109

https://robertostefanettinavblog.wordpress.com/2016/09/07/how-to-manage-nav-notifications-by-cal/

 

For more information on Dynamics NAV 2017 features, please visit our website. 

If you are interested in NAV development, check out our collection of NAV Development Blogs.

Blog Tags: 
Read ArcherPoint's Blog Follow us on Twitter Follow us on Facebook Follow us on LinkedIn Link to our RSS feed Join us on Google+ Watch us on YouTube
Get Help Now