//Gives me a list of all the Programs that User has access too. UserSetupLine.SETRANGE("User ID", USERID); IF UserSetupLine.FINDSET THEN BEGIN REPEAT IF AllUserProgram = '' THEN AllUserProgram := UserSetupLine."Program" ELSE AllUserProgram := UserSetupLine."Program" + '|' + AllUserProgram; UNTIL UserSetupLine.NEXT=0; END; //Gives me a list of All Programs of the contact IF Contact2.FINDSET THEN BEGIN REPEAT ProgramRelationship.SETCURRENTKEY(Type,"No.", "Program"); ProgramRelationship.SETRANGE(Type, 'Contact'); ProgramRelationship.SETRANGE("No.", Contact2."No."); IF ProgramRelationship.FINDSET THEN BEGIN REPEAT IF AllContactProgram = '' THEN AllContactProgram := ProgramRelationship."Program" ELSE AllContactProgram := ProgramRelationship."Program" + '|' + AllContactProgram; UNTIL ProgramRelationship.NEXT =0; //Intersection between AllContactProgram and AllUserProgram ProgramRelationship.SETCURRENTKEY("No.", "Program"); ProgRelationship.SETRANGE("No.", Contact2."No."); ProgRelationship.SETFILTER("Program", '(' + AllUserProgram + ')' + '&' + '(' + AllContactProgram + ')'); IF ProgRelationship.FIND('-') THEN BEGIN //Temporary Contact variable to store all the Contacts that match/can be seen by the user. TempContact.INIT; TempContact."No." := Contact2."No."; TempContact.INSERT; END; END; UNTIL Contact2.NEXT=0; END;
TempContact.COPY(Rec); RecordFound := TempContact.FIND(Which); Rec := TempContact; EXIT(RecordFound);
TempContact.COPY(Rec); Found := TempContact.NEXT(Steps); Rec := TempContact; EXIT(Found);
Comments
Then you should get all contacts without to need to loop each one.
I had an idea, but I am not sure if this would work or even if it is possible. As soon as user opens NAV, I can run the code in the background and prefetch the filtered Contact list that the user should see so by the time user gets to Contact cards, the filter is already applied. Is this possible. If yes, how?
I'm not sure it will perform better....
/Juha
First of all, thats a genius way of doing it. =D> =D>
I tried what you suggested and the performance is a lot better. But what is happening now is that lets say I open Contact List from the Contact Card, I get the following message:
OR, lets say the system finds the 3 contact that match the user permission. When I am on the 3 contact card and I hit the Next button, system gives me the Quote that I mentioned above and the message is displayed for almost a min before I get an empty contact record.
Any ideas or suggestions as to how I can combat this?
I don’t think its possible to prefetch the records in background when user log in.
How often is the user setup and ProgramRelationship changed? If it’s somehow possible to prefetch the list, you wouldn’t be able to see changes made after user logged in.
Only other solution I can think of is to make a new table with UserID and ContactNo which is updated whenever the usersetup or programrelationship is changed. You can then use this table instead of the TempContact in OnFindRecord and OnNextRecord. It will make the update slow, so its a question of what is the least annoying, I think.
/Juha
Let me give saving users id and contact no. on a separate table a try.