Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to open form of new document with filled values

Forum

Search UsersRules
How to open form of new document with filled values
#1
Active user
Points:: 0
Joined:: Sep 18, 2012

Hello everyone,
I need to open new document form with filled values.
I did something like below but it creates documents and writes it. Without Doc.Write() it doesn't work (values are not filled as I want). Could you tell me how I can do the same to open document form with filled values (Warehouse, Date etc and ItemsLines) but not written yet?

Code
Procedure OpenFormGoodsIssue()
  Doc = CreateNewGoodsIssueDocument(Parameters.Zlecenie,"Magazyn");
   FullDocumentFormName =  "Document.GoodsIssue.ObjectForm";
   Param = New Structure("Key",Doc);
   OpenForm(FullDocumentFormName,Param,ThisForm,,,,,);
EndProcedure

Function CreateNewGoodsIssueDocument(
Query = New Query;
   Query.Text = query text here...
   
Selection = Query.Execute().Select();   
   
Doc = Documents.GoodsIssue.CreateDocument();    
Doc.Warehouse=Catalogs.Warehouses.FindByDescription(WarehouseDescription);
Doc.OperationType = Enums.OperationTypesGoodsIssue.Usage;
Doc.ZlecenieNaprawy = ZlecenieNaprawy;
Doc.Date = CurrentDate();          
   
   While Selection.Next() Do
                NewLine = Doc.ItemsLines.Add();
      NewLine.Item = Selection.Item;
      NewLine.UnitOfMeasure = Selection.Item.BaseUnitOfMeasure;
      NewLine.Quantity = Selection.QuantityBalance;
   EndDo;
   Doc.Write();
   Return Doc.Ref; 
EndFunction


Thank you in advance for any help!
Regards,
Kris

Profile
#2
Active user
Points:: 0
Joined:: Mar 10, 2017

Hello Kris,

Here is a block of the code to help you. This should work for managed form application.

Code
&AtServerNoContext
Procedure FillDataOnServer(FormData)

   DocObj =FormDataToValue(FormData,Type("DocumentObject.ProductReceipt"));
   
   
   ///here is the block where you can input your data to unsaved document
   
      DocObj.Date = Date(2019,04,23); //adding document attributes
      DocObj.Number = "000001"; 
      
      newTabularLine = DocObj.Products.Add();  //adding to tabular part of document
      newTabularLine.Price =  1000;
      newTabularLine.Quantity =  2;
      newTabularLine.Amount =  newTabularLine.Price * newTabularLine.Quantity;
      
   ///here is the block where you can input your data to unsaved document

      ValueToFormData(DocObj,FormData);
   
EndProcedure

&AtClient
Procedure OpenFormUnsavedDocument(Command)
   
   NewDocumentForm = GetForm("Document.ProductReceipt.Form.DocumentForm");
   
   FormData = NewDocumentForm.Object;

   FillDataOnServer(FormData);
   
   CopyFormData(FormData, NewDocumentForm.Object);
   
   NewDocumentForm.Open() ; //open unsaved form
   
EndProcedure



Best regards,
Alex

Profile
#3
Active user
Points:: 0
Joined:: Sep 18, 2012

Hello Alex,
it works fine! :)
Thank you very much.
Kris

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.