How can I ensure that when I add a row in the Delivery Term tabular section of my Sales Order document, it only includes products that are already listed in the Inventory tabular section? Both tabular sections refer to the Product catalog.
as I understand it, you want to fill the "Delivery Term" tab only with those products that are in the "Products" tab? Right?
Maybe you could simplify the task and completely prohibit the user from creating new rows in the "Delivery Term" tab?
And fill this tab automatically, with the products that are in the document. That is, the user added a product to the "Products" tab - and this product immediately appeared in the "Delivery terms" tab.
This will speed up the user's work and avoid errors in work...
The requirement is not like that. What the user wants is to add the product delivery term manually, and the products that are in the delivery term should be the products from the Inventory tabular section.
With such requirements, this can be done as follows.
In 1C, the atributs have a parameter "ChoiceParameters" (see screenshot 1).
This parameter allows us to set a filter on the data, and the user will be able to select only the data that we provide him.
This filter can be set directly in the Designer (screenshot 2). But this method does not suit us, since we need to dynamically change the data in the filter.
Therefore, we can implement the setup of this filter programmatically:
Code
&AtServer
Procedure setupChoiceParameters()
parametersForChoice = New Array;
query = New Query;
query.Text = "SELECT
| SalesInvoiceProducts.Product AS Product
|FROM
| Document.SalesInvoice.Products AS SalesInvoiceProducts
|WHERE
| SalesInvoiceProducts.Ref = &SalesInvoice";
query.SetParameter("SalesInvoice", Object.Ref);
arrayProducts = query.Execute().Unload().UnloadColumn("Product");
parameter = New ChoiceParameter("Filter.Ref", New FixedArray(arrayProducts));
parametersForChoice.Add(parameter);
ThisForm.Items.DeliveryTermsProduct.ChoiceParameters = New FixedArray(parametersForChoice);
EndProcedure
and call the "setupChoiceParameters" procedure when we need it.
For example in screenshot 3, this procedure is called when creating on the server . In general, this procedure should be called whenever the data in the table part of the document changes. I leave this to you to implement
First, you need to make sure that the code you created actually runs.
To do this, you need to set a breakpoint in the Designer, and then run 1C in debug mode.
If the "setupChoiceParameters" procedure runs, you need to see if this procedure sets all the necessary variables during its operation.
If the "setupChoiceParameters" procedure does not run at all (that is, the program does not stop at the breakpoint), then you need to understand whether your extension is connected at all.
When i set breakpoint, the program stop at the breakpoint. So, my code actually runs but why still cannot get the product from tabular inventory in my tabular deliveryterm?
Code
&AtServer
Procedure setupChoiceParameters()
parametersForChoice = New Array;
query = New Query;
query.Text ="SELECT
| SalesOrderInventory.Products AS Products
|FROM
| Document.SalesOrder.Inventory AS SalesOrderInventory
|WHERE
| SalesOrderInventory.Products = &SalesOrder";
query.SetParameter("SalesOrder", Object.Ref);
arrayProducts = query.Execute().Unload().UnloadColumn("Products");
parameter = New ChoiceParameter("Filter.Ref", New FixedArray(arrayProducts));
parametersForChoice.Add(parameter);
ThisForm.Items.DeliveryTermTable.ChildItems.Product.ChoiceParameters = New FixedArray(parametersForChoice);
EndProcedure
&After("OnCreateAtServer")
Procedure Ext1_OnCreateAtServer(Cancel, StandardProcessing)
setupChoiceParameters();
EndProcedure
First you would to set a so-called "breakpoint" - screenshot 1. Just double-click to do this.
Then run 1C in operating mode, open the required document (in my case it is SalesInvoice) and the program will stop at this point. Look at screenshot 2 - you can see that the program has stopped.
In the next step, select the variable whose value you want to see and then do as in screenshot 3.
As you can see, I looked at the value of the variable "arrayProducts". This is an array, and it stores one value "Product_1".
This means that your query returns an empty value. So we need to check why it returns an empty value...
If we compare the code I gave you (screenshot 1) with the code you are trying to run (screenshot 2), it will immediately become clear what the error is.
You pass a parameter (SalesOrder) to the request, but you compare this parameter simply with the table part of the document. This is an error!
I compare this parameter with a reference to the document itself (SalesInvoiceProducts.Ref).