web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Saving printer settings

(0) ShareShare
ReportReport
Posted on by 931

Hi All,

I have a form with two buttons(Print and Options)

Print button passes the current record to the report and prints it on screen.

In Options button i have SysPrintForm.

Now where i  got stucked is, when i click the options button, it will open the SysPrintForm, and if i select any printer that printer should be saved for the current user.

The next time when the same user hit Print Button, the report should go directly to the printer as well as in the screen.

Is this possible??

Any ideas?

*This post is locked for comments

I have the same question (0)
  • ThivaKar Profile Picture
    931 on at

    Below are the steps so far i tried to achieve this .

    Created a table with two fields. User and Options(Container field).

    When the user hits Options button,

    select User from TableA

           where TableA.User == XUserInfo::find(false, curuserid()).Name;

           if(TableA.Options)

           {

           printJobSettings = new PrintJobSettings(TableA.Options);

           printJobSettings.printerSettings(formstr(SysPrintForm));

           TableA.Options = printJobSettings.packPrintJobSettings();

           select forupdate label where  TableA.User == XUserInfo::find(false, curuserid()).Name;

           TableA.Options= printJobSettings.packPrintJobSettings();

           ttsbegin;

           TableA.update();

           ttscommit;

           }

          else

          {

           printJobSettings = new PrintJobSettings(TableA.Options);

           printJobSettings.printerSettings(formstr(SysPrintForm));

           TableA.Options = printJobSettings.packPrintJobSettings();

           TableA.User = XUserInfo::find(false, curuserid()).Name;

           TableA.insert();

            }

    While debugging i can see the printer is saved in the Options field.

    But, it is not storing this record.

    If it stores, then, in the report init() method, i can select printer from this table

    and pack it to send it to the printer.

    I might be completely wrong.

    But please advice alternate solution or solution to my above method.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    If insert() or update() gets called, if it doesn't throw any exception and if the transaction isn't aborted later, the record is stored in database. If you don't find it there later, maybe you have a problem in the code reading the value, not with writing.

    By the way, the condition shouldn't be based on the Options field. If you had a record with empty Options, the condition would return false and your code would try to insert a duplicate record. Use RecId to check if a record has been found or not.

  • ThivaKar Profile Picture
    931 on at

    Ya i did use RecId in the condtions, but it doesn't return the options value.

    I dont know where iam wrong in my code and that is why i posted here to get idea on what is wrong.

    I deleted the table data. And if hit options. a record is inserted.

    But the second time if i hit options, the record is available but there is no value in the container.

    PS: As far i understood i couldn't think any other way to achieve this.

    So, could you please guide me in the right path to do this.

  • ThivaKar Profile Picture
    931 on at

    Still stuck on this one.

    Could someone help please

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Aha, so now you're saying that the record does get saved, but that the Options field doesn't contain the data you expect, right?

    How exactly are you verifying the binary data stored in Options? I suspect that you're not doing it right.

  • ThivaKar Profile Picture
    931 on at

    Yeah exactly. Option field doesn't contain the data i expect.

    I'm verifying it by debugging.

    I hit the options button the code mentioned above, searches the record in the table.

    If the record is not found, it inserts the data for the field user-Current User and for the Options field the selected printer.

    TableA.Options = printJobSettings.packPrintJobSettings();

    It inserts successfully.

    Then if i hit it again, the record is found in the table , but options field doesn't have the data.

    if(TableA.RecId)

    {    

    printJobSettings = new PrintJobSettings(TableA.Options);// This should return the value, so that i can view my last saved printer.

    }

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    What happens if you run the code above?

    Did you verify whether Options == conNull() or not?

    Did you have data in printJobSettings when you were serializing it to Options?

  • ThivaKar Profile Picture
    931 on at

    If the record is not found in the table.

    then in the else part.

    1st line, i have default printer in the printjobsettings.

    2nd line, opens SysPrintForm.

    3rd line, i have the selected printer in the printJobSettings.

    Inserts sucessfully.

    If i execute it again,

    the record is found in the table,

    if condition passes,

    in the 1st line of if, i should have the selected printer in the printJobSettings,

    but it give me the default printer in printJobSettings.

  • ThivaKar Profile Picture
    931 on at

    I don't have data in printJobSettings under if condition.

  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at

    Sorry, but I'm not sure what's your definition of " under if condition". If "I don't have data in printJobSettings under if condition" means that you don't have any data in the object that you're saving to database, you can't expect the data to magically appear in the field. You put an empty object there, you get an empty object back - everything is correct.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans