Printer Selection table permissions for regular user

pfedory
Member Posts: 3
Hello,
I have a codeunit which modifies the printer selection for a report. Before you print the report, it is changed to our own printer and after, the printer is restored to the original printer. This works for a super user, but not for a regular user. I have added rights for the printer selection table and table data for the regular user, however when I run the report, NAV crashes sometimes when I'm setting the printer selection and sometimes when I'm restoring the printer selection.
Does anyone know why this would happen for a regular user but not a super user? Are there any other permissions needed aside from the printer selection table and table data which has already been added?
Here is a snippet from the codeunit which runs the report:
Here is the definition for SetPrinterSelection:
Here is the definition for Restore Printer Selection:
Any help would be greatly appreciated.
Regards,
Paul Fedory
I have a codeunit which modifies the printer selection for a report. Before you print the report, it is changed to our own printer and after, the printer is restored to the original printer. This works for a super user, but not for a regular user. I have added rights for the printer selection table and table data for the regular user, however when I run the report, NAV crashes sometimes when I'm setting the printer selection and sometimes when I'm restoring the printer selection.
Does anyone know why this would happen for a regular user but not a super user? Are there any other permissions needed aside from the printer selection table and table data which has already been added?
Here is a snippet from the codeunit which runs the report:
SetPrinterSelection; REPORT.RUNMODAL(TheReportID, FALSE, FALSE, Records); RestorePrinterSelection;
Here is the definition for SetPrinterSelection:
SetPrinterSelection() // delete any records in the temp printer selections record TempPrinterSelections.RESET; TempPrinterSelections.DELETEALL(FALSE); // filter the printer selections by report id and user id PrinterSelections.RESET; PrinterSelections.SETRANGE(PrinterSelections."Report ID", TheReportID); PrinterSelections.SETRANGE(PrinterSelections."User ID", USERID); // if a record exists for this user and report we need to save it off and modify it // there cannot be more than one record with these filters IF PrinterSelections.FIND('-') THEN BEGIN // save the printer selection into the temporary table TempPrinterSelections := PrinterSelections; TempPrinterSelections.INSERT; // change the printer selections record so it will now print to the api printer PrinterSelections."Printer Name" := 'Zetadocs Automation Subsystem'; PrinterSelections.MODIFY; END ELSE BEGIN // if there are no records we need to make a new one for this user and report PrinterSelections.INIT; PrinterSelections."Report ID" := TheReportID; PrinterSelections."User ID" := USERID; PrinterSelections."Printer Name" := 'Zetadocs Automation Subsystem'; PrinterSelections.INSERT; END; // make sure the transaction is committed to the database COMMIT;
Here is the definition for Restore Printer Selection:
RestorePrinterSelection() // filter the printer selections table so we will see the selections for this report PrinterSelections.RESET; PrinterSelections.SETRANGE(PrinterSelections."Report ID", TheReportID); PrinterSelections.SETRANGE(PrinterSelections."User ID", USERID); // We should always find one record because we put it there IF PrinterSelections.FIND('-') THEN BEGIN TempPrinterSelections.RESET; IF TempPrinterSelections.FIND('-') THEN BEGIN PrinterSelections := TempPrinterSelections; PrinterSelections.MODIFY; END ELSE BEGIN PrinterSelections.DELETE; END; END; COMMIT;
Any help would be greatly appreciated.
Regards,
Paul Fedory
0
Comments
-
Sorry, I should have added the error I'm seeing just before NAV crashes.
The error just before it crashes is as follows:
Another user has modified the record for this Printer Selection after you retrieved it from the database.
Enter your changes again in the updated window, or start the interrupted activity again.
Identification fields and values:
User ID='<regular user ID>',Report ID='205'.
Also, this problem occurs on NAV 4.0.0 -
1) Try to assign only the needed fields instead assigning whole record when restoring the record.
2) You have one big hole in your process - COMMIT. If someone will use this code somewhere, you could have big mess in the database. E.g. when the report fail, the setting will not be restored, and thus next call will "backup" wrong setting and you will never get back the original setting in the table. And of course the commit could break other transactions already running before this code...0 -
Yep, avoid commits whenever possible.
Incidentally, that error is caused by modifying the primary key of a record and then not retrieving it again from the database. So do a GET or FIND later on in your code.
I believe I have seen several posts on this, specifically about printing to PDF so you could find some code there.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions