Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to create print forms dynamically

Forum

Search UsersRules
How to create print forms dynamically
#1
Active user
Points:: 0
Joined:: Feb 8, 2013

Hello!

Is there are any possibility to put standard command of spreadsheet document into command bar using a code?

We create some spreadsheet documents in form through code, so we want to add "Page Setup" and "Preview" commands in command bar for those spreadsheet documents.

Example is PrintingDocuments Form from SL.

Thank you.

Profile
#2
Guest
Points::
Joined::

Hello, Pavel!

I think it is better to place those commands on the form in Designer mode and after this, change their visibility using the script.

Profile
#3
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

Hello,

I create spreadsheet document through script, so i can not do it in designer mode.

Because number of spreadsheets is dynamically. As an example i give you form from SL.

Is there any variants to solve it using a script?

Profile
#4
Guest
Points::
Joined::

Hello, Pavel!

Here is an example that I made for you on how to add a button on the form using the script:

Code
&AtClient
Procedure OnOpen(Cancel)
   AddButtonServer();
EndProcedure

&AtServer
Procedure AddButtonServer()
   
   Command = Commands.Add("Button");
   Command.Action = "ButtonAction";
   Command.Title = NStr("en = 'New button'");
   
   Item = Items.Add("FormButton", Type("FormButton"), ThisForm);
   Item.Type = FormButtonType.UsualButton;
   Item.CommandName = "Button";

EndProcedure

&AtClient
Procedure ButtonAction()
  ShowMessageBox(, NStr("en = 'Some action performed.'"));
EndProcedure

Profile
#5
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

Dear Timofey,

Thank you for response, but unfortunately it's not what i'm asking about.

I know how to create button using a script. My task is create buttons for predefined commands of spreadsheet document such as "Page Setup" or "Preview".

Thank you.

Profile
#6
Guest
Points::
Joined::

Pavel,

Unfortunately, adding a standard command in this way is not possible, you need to create a procedure that will execute analog of standard command and assign this action to the button.

For example:

Code
&AtClient
Procedure ButtonAction()
   SpreadsheetDocument.TopMargin = 5;
   SpreadsheetDocument.BottomMargin = 5;
   SpreadsheetDocument.LeftMargin = 5;
   SpreadsheetDocument.RightMargin = 5;
   SpreadsheetDocument.PageOrientation = PageOrientation.Landscape;
EndProcedure

Thus it is easier to create a separate form where place attribute of the SpreadsheetDocument type and you will have those buttons available automatically. Same as it was implemented in 1C:Subsystems Library 1.0.

You could open this form sending the generated print form as a parameter with your dynamic buttons.

Profile
#7
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

Does 1C have plans to add such functional in future releases of platform. I mean possibility to assign buttons added by using script with standart commands?

Thank you.

Profile
#8
Guest
Points::
Joined::

This is not yet clear for me that this feature is useful.
Would you please explain use cases with examples?
If they will be reasonable, I could submit the feature request for you.

Profile
#9
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

As i wrote above, we are using SL provided by 1C and in case of common form "Printing Documents" where all spreadsheet documents generated dynamically using a script we want to put such commands as "Preview" and "Page Setup" in command bar because it will be useful and clear for users (more useful than in window bar at the top right side).

Why you recommend to do it like it was in SL v1.0 if current version of SL change vision for this mechanism?

So that's why i am asking about this feature because its a huge scope of work to create new PrintingDocuments form and in general we would like to use SL version and update it everytime.

Profile
#10
Guest
Points::
Joined::

Pavel,

I made a more complete example for you.

Here two buttons are added to the form programmatically, each of them generate an individual print form.

After this they are opened in an additional form where standard buttons for the spreadsheet document print preview and page setup are added.

Think, this covers your needs without an enhancement that you are asking for.

Code
&AtClient
Procedure OnOpen(Cancel)

   AddButtonServer("Invoice");
   AddButtonServer("Receipt");

EndProcedure

&AtServer
Procedure AddButtonServer(PrintFormName)
   
   CommandName = "Open" + PrintFormName;
   
   Command = Commands.Add(CommandName);
   Command.Action = CommandName;
   Command.Title = StrReplace(NStr("en = 'Open %1'"), "%1", PrintFormName);
   
   Item = Items.Add("Form" + CommandName, Type("FormButton"), ThisForm);
   Item.Type = FormButtonType.UsualButton;
   Item.CommandName = CommandName;

EndProcedure

&AtClient
Procedure OpenInvoice()

   PrintForm = GeneratePrintForm("Invoice");
   
   FormParameters = New Structure;
   FormParameters.Insert("PrintForm", PrintForm);
   
   OpenForm("DataProcessor.AddButtonTest.Form.PrintForm", FormParameters);
   
EndProcedure

&AtClient
Procedure OpenReceipt()

   PrintForm = GeneratePrintForm("Receipt");
   
   FormParameters = New Structure;
   FormParameters.Insert("PrintForm", PrintForm);
   
   OpenForm("DataProcessor.AddButtonTest.Form.PrintForm", FormParameters);
   
EndProcedure

&AtServer
Function GeneratePrintForm(TemplateName)

   Output = New SpreadsheetDocument;
   
   DataProcessorObject = FormAttributeToValue("Object");
   Template = DataProcessorObject.GetTemplate(TemplateName);
   
   Header = Template.GetArea("Header");
   Output.Put(Header);
   
   Row = Template.GetArea("Row");
   Total = 0;
   For I = 0 To 2 Do
      Price = 12;
      Quantity = 2;
      Row.Parameters.Item = NStr("en = 'Item'");
      Row.Parameters.Price = Price;
      Row.Parameters.Quantity = Quantity;
      Row.Parameters.Total = Price * Quantity;
      Total = Total + Row.Parameters.Total;
      Output.Put(Row);
   EndDo;
   
   Footer = Template.GetArea("Footer");
   Footer.Parameters.Total = Total;
   Output.Put(Footer);
   
   Return Output;
   
EndFunction

When the form is already opened, its content does not update. To have all print forms opened in separate windows you need to specify the difference between forms by setting the PrintForm parameter as the key parameter.
To display the spreadsheet document, simply assign it to the form attribute:
Code
&AtServer
Procedure OnCreateAtServer(Cancel, StandardProcessing)
   
   SpreadsheetDocument = Parameters.PrintForm;
   
EndProcedure


Please see the attached configuration dump.

Profile
#11
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

Unfortunately its not cover my needs.

In general i dont understand why you try to push me to create a new form for printforms if we already have a very functional form from SL, which provide much more functionality than you put in your example. And in case of your suggestion we will lose all this functionality. As i told we want to use all functionality from SL form and we need just to have a possibility to add those 2 standard commands for spreadsheet document.

Profile
#12
Guest
Points::
Joined::

Hello, Pavel.

I'm trying to solve your problem. If it is not urgent, I submitted the feature request for you. But I'm afraid it might take a long time for this feature to be developed. If it will be accepted.

Profile
#13
Active user
Points:: 0
Joined:: Feb 8, 2013

Timofey Bugaevsky,

it's not very urgent.

In our vision this feature will help us to make our solution more friendly for users.

Please keep in touch regarding a decision of your developers.

Thank you.

Profile
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)



© 1C LLC. All rights reserved
1C Company respects the privacy of our customers and visitors
to our Web-site.