Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > Get Product each Tabular Section on Document

Forum

Search UsersRules
Get Product each Tabular Section on Document
#1
Just came
Points:: 0
Joined:: Oct 16, 2024

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.

Profile
#2
Administrator
Points:: 0
Joined:: Oct 3, 2019

Hello Ahmad,

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...

How do you like this idea?

Profile
#3
Just came
Points:: 0
Joined:: Oct 16, 2024

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.

Profile
#4
Administrator
Points:: 0
Joined:: Oct 3, 2019

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 :-)

Profile
#5
Just came
Points:: 0
Joined:: Oct 16, 2024

I've tried this code but still not working, where is the problem?

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.Ref = &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

Profile
#6
Administrator
Points:: 0
Joined:: Oct 3, 2019

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.

Profile
#7
Just came
Points:: 0
Joined:: Oct 16, 2024

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

Profile
#8
Just came
Points:: 0
Joined:: Oct 16, 2024

The products (16) should be listed in DeliveryTerm product option like the picture below.

Profile
#9
Administrator
Points:: 0
Joined:: Oct 3, 2019

Look (and show me) what values ​​you have in:

1. Array "arrayProducts"

2. In the array "parametersForChoice"

Profile
#10
Just came
Points:: 0
Joined:: Oct 16, 2024

What should i do to show the value? I'm sorry, but i don't know how

Profile
#11
Administrator
Points:: 0
Joined:: Oct 3, 2019

It's very simple.

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".

Profile
#12
Just came
Points:: 0
Joined:: Oct 16, 2024

Why there is no value in my arrayProducts?

Profile
#13
Administrator
Points:: 0
Joined:: Oct 3, 2019

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).

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.