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:
- A new data type: Notification. This is a very complex type that include a dictionary in his methods GETDATA y SETDATA, and reflection in ADDACTION method, where a function inside a Codeunit could be attached to the notification: https://msdn.microsoft.com/en-us/dynamics-nav/notifications-developing
- A new pattern, explaining without any doubt how to work with notifications: https://community.dynamics.com/nav/w/designpatterns/284.in-context-notifications
- “My notifications” page behavior is related with Discovery event pattern: https://community.dynamics.com/nav/w/designpatterns/271.discovery-event
- Filtering notifications involve a new data type raised in 2016: FILTERPAGEBUILDER. Is a special kind of page that collect filters from a record: https://msdn.microsoft.com/en-us/library/dn951463(v=nav.90).aspx
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.

Like
Report
*This post is locked for comments