web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Jesús Almaraz blog / Notifications review and op...

Notifications review and optimizations.

Jalmaraz Profile Picture Jalmaraz 669

Context

Since NAV 2017 we have a really good improvement: Notifications. Notifications have two exciting sides:

  • Friendlier context information than a message box or a modal page. Is applied in custom credit test, item availability test in sales, and many more.
  • It´s possible to disable these notifications in "My notifications". Also, we can specify a filter conditions in a record, to set if the notification will be applied.

Notifications isn’t a little feature.

Notifications deserve all our consideration. We know, in NAV 2017 version the main new is extensions, but notifications is a great feature too. There are many important concepts related to notifications:

You see, notifications is a worthy main feature of 2017!!

Filtering My notifications: Have we a problem?

Be able to filter Notifications could be a time execution problem.

We have this scenario: we filter a set of items to apply the sales line stock warning. What might happen if we have a thousand items in this filter?: the notifications read and check all the filtered records, until the unique key match with the record we are checking. This could be slow, only to know the notification is able to a record.

A look to the checking code

Let see the table 1518 "My notifications" function "IsEnableForRecord":

 

IsEnabledForRecord(NotificationId : GUID;Record : Variant) : Boolean

IF NOT IsEnabled(NotificationId) THEN
  EXIT(FALSE);

IF NOT Record.ISRECORD THEN
  EXIT(TRUE);

RecordRefPassed.GETTABLE(Record);

GetFilteredRecord(RecordRef,GetFiltersAsText);

IF RecordRef.NUMBER <> RecordRefPassed.NUMBER THEN
  EXIT(TRUE);

PrimaryKeyRef := RecordRef.KEYINDEX(1);
IF RecordRef.FINDSET(FALSE,FALSE) THEN
  REPEAT
    MatchFound := TRUE;
    FieldIndex := 1;
    WHILE MatchFound AND (FieldIndex <= PrimaryKeyRef.FIELDCOUNT) DO BEGIN
      FieldRef := RecordRef.FIELDINDEX(FieldIndex);
      FieldRefPassed := RecordRefPassed.FIELDINDEX(FieldIndex);
      MatchFound := MatchFound AND (FieldRef.VALUE = FieldRefPassed.VALUE);
      FieldIndex += 1;
    END;
  UNTIL MatchFound OR (RecordRef.NEXT = 0);

EXIT(MatchFound);

 

Notice that could be slower if the record isn´t in the set.

How could be fixed?

Adding this blue code only check a single record set filtering by all the notifications filters and the primary key:

...........

GetFilteredRecord(RecordRef,GetFiltersAsText);
IF RecordRef.NUMBER <> RecordRefPassed.NUMBER THEN
  EXIT(TRUE);
//Begin of modification
RecordRef.FILTERGROUP(2);
RecordRefPassed.SETRECFILTER;
RecordRef.SETVIEW(RecordRefPassed.GETVIEW);
EXIT(RecordRef.FINDFIRST);
////All code above not needed!!!!!!!
PrimaryKeyRef := RecordRef.KEYINDEX(1);
IF RecordRef.FINDSET(FALSE,FALSE) THEN
  REPEAT

..................

Comments

Notice that this fix change standard NAV code: if you don´t have time response problems, don´t do it.

This code works and improves time response, but it´s only my own solution.

New code can be placed in a function and called by hook.

Comments

*This post is locked for comments