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
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.
I don't have data in printJobSettings under if condition.
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.
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?
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.
}
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.
Still stuck on this one.
Could someone help please
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.
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.
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.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,232 Super User 2024 Season 2
Martin Dráb 230,064 Most Valuable Professional
nmaenpaa 101,156