Tuesday, 29 January 2008

Marking Records - Gotcha!

Here’s a simple little modification that requires a developer’s license (you need to write some code.) In version 5.0 I have a Job No. field in my G/L Journal and I want to be able to filter my G/L Journal so that only records that have a Job No. that is blocked are displayed. My journal gets created through an interface (in case you were wondering how these lines got entered.)


I knew I could to this by Marking the records where the job was blocked and then showing only Marked records. This is the Gotcha: the default parameter for the Mark and MarkedOnly functions is false meaning it will effectively not do anything. The online help tells you this but still it’s a bit of a puzzler if you don’t do these things very often.

My code for Only Records with Blocked Jobs is as follows:

CLEARMARKS;

IF Rec.FINDSET THEN
REPEAT
IF "Job No." <> '' THEN BEGIN
lJob.GET("Job No.");
IF lJob.Blocked <> lJob.Blocked::" " THEN BEGIN
lBlockedJobsFound := TRUE;
Rec.MARK(TRUE);
END;
END;
UNTIL Rec.NEXT = 0;

IF lBlockedJobsFound THEN
MARKEDONLY(TRUE)
ELSE BEGIN
MARKEDONLY(FALSE);
MESSAGE('No blocked jobs found in this journal batch.');
END;

My code for showing all records is as follows:

CLEARMARKS;
MARKEDONLY(FALSE);

Still, it would be nice if the end-user could have applied this filter as they would be able to in Microsoft CRM. Maybe one day future versions of NAV will allow the user to define filters using related tables too.

No comments: