Record filtration in OnOpenPage trigger

I want to show projects which have some specific permissions to the user which opening Projects list page.

I have written below code to calculate the permissions and store records in tempJob table.

what is the best way to apply those jobs from temporory variable to rec variable?


JobTMP.DELETEALL;
Job.RESET;
Job.SETFILTER(Blocked,'%1|%2',Job.Blocked::" ",Job.Blocked::Posting);
IF Job.FINDSET THEN
REPEAT
IF (Job."Person Responsible" = UserSetupRec."Resource Code") OR (Job."Project Manager" = UserSetupRec."Resource Code") THEN BEGIN
JobTMP := Job;
IF JobTMP.INSERT THEN
JobTMP.MODIFY;
END ELSE BEGIN

IF LimitProjectsandTasksLookup(UserSetupRec."Resource Code",Job."No.",'') THEN BEGIN
JobTMP := Job;
IF JobTMP.INSERT THEN
JobTMP.MODIFY;
END;

END;

UNTIL Job.NEXT = 0;

  • Filtering on Temporary table on OnOpenpage will not work, the filtering has to be on the table itself. I would create a function and return a text return value and call the function on OnOpenPage of the Job card and compare it against a field on the Job card, then use FILTERGROUP(2) and FILTERGROUP(0), this way your filter will stay put even if the user clicks on Showall, if you use temporary table the filters will be lost when user clicks on Showall on the page.
  • In reply to sbhatbng:

    I am looking for suggestions to copy the filters from temp table to original record and filtergroups will come there.

  • In reply to Mohana:

    How about when you run through the table store the field values you want to filter in an array and then OnAfterGetRecord of the page check if the current record values is part of the array and if not part of the array then skip the record Or you might have to waste a table for this which I always hate for filtering records, write the transactions to a table and then compare the values against the record a crude way which would be my last resort.
  • In reply to sbhatbng:

    This is onpage level. can we skip in page level as well? I think you mean report?

  • In reply to Mohana:

    Ok, I thought it was a report, my bad. Ok, on the page the only option I can think off is create a new Boolean field in Job table something like Showvalue type boolean, OnOpenPage you call a function named FilterValueRecords, In that function put your above code, instead of writing it into a temporary table Jobtmp update the new boolean field by modifying the record you created in the Job table viz Showvalue, after the function is run something like below

    FilterValuerecords; //Updates the Showvalue new field you create
    FILTERGROUP(2)
    SETFILTER(SHOWVALUE,TRUE);
    FILTERGROUP(0)

    Just make sure that in your function to reset the Showvalue boolean field to false which will be your first statement, like modifyall(showvalue,false);
  • In reply to sbhatbng:

    Thank you and it is failing when 2 users are simultaneously accessing projects list at a time as both are trying to modify the record.
    any other suggestions?

  • In reply to Mohana:

    Ok, How about you update the new boolean field right at the Onvalidate trigger of the table for fields Person responsible and Project manager in Job table and Resource code in usersetup table. whenever these 3 fields are entered/modified/removed from the tables then manipulate the new boolean field Showvalue which I mentioned to add in the Job table. Currently if you have Job and usersetup table populated write a processing report to update the new boolean field one time for all the records and then going forward your onvalidate table trigger will take care of new records and use this new boolean field on the page to filter.
  • In reply to sbhatbng:

    I have to show the project to project manager and also person responsible when they open the list. How can I use same field for both?
  • In reply to Mohana:

    I am not sure what Project is in your case, Is it a field or a page ??
  • In reply to sbhatbng:

    Page like jobs list
  • In reply to Mohana:

    Found solution here. Thank you..
Related