Desktop version

Main > Forum > 1C:Enterprise Platform > 1C:Enterprise – Business applications platform > How to find out if the dynamic list is not empty?

Forum

Search UsersRules
How to find out if the dynamic list is not empty?
#1
Active user
Points:: 3
Joined:: Sep 16, 2011

And one more question: how can I find out if the DynamicList contain any data?
The task is to suggest adding a first item to the empty list. It has some filters so checking if my catalog is empty is not the thing which will help here.

Profile
#2
Just came
Points:: 12
Joined:: Nov 23, 2011

I think you have to:
1. Read all filters which have "use = true"
2. Write a query to this object (whith all filters from 1)

Profile
#3
Active user
Points:: 3
Joined:: Sep 16, 2011

:( It is a complicated query so I would not like to repeat it due to it's hard to support. If there is a way to use the one which is built in into the DynamicList? Or maybe there is a simpler way? How can I understand if there is any item displayed in the form item having this DynamicList as a data source?

Profile
#4
Active user
Points:: 2
Joined:: Sep 16, 2011

Try to check if the CurrentRow is Undefined for your list the DynamicList is empty.

Profile
#5
Active user
Points:: 1
Joined:: Nov 24, 2011

#4 Not working because When You change filter and list was empty befor and filled after changing filter you'll have CurrentRow is Undefined  but there is data in list. I think Silvia need something like

Code
   QueryBuilder = New QueryBuilder;
   BuilderText =  "SELECT
               |   Order.Ref
               |FROM
               |   Document.Order AS Order";
   QueryBuilder.Text = BuilderText;
   DataSourceDescription = New DataSourceDescription(DocListControl);
   QueryBuilder.DataSource = DataSourceDescription;
   
   QueryBuilder.Execute();
   TZ = QueryBuilder.Result.Unload();
   If TZ.Count() > 0 Then
      //not empty
   Else
      //empty
   EndIf;

but this need big memory for large datas. I think Silvia have to use another algoritms, whithout checking data in controls.

Profile
#6
Just came
Points:: 0
Joined:: Nov 23, 2011

Silvia Ashley, good question!
The fact that the filling DynamicList may influence the selection of previously established Programming. On the other hand - I never will have to solve such problems, but just can not come across ...
Figure 1:
Perform as suggested earlier request but we do not need to perform the entire query, not just run " Select * ..." but "Select FIRST 1 * ...."
Figure 2:
forcibly reset selections if they are installed, check for emptiness, "Items.List.CurrentRow" and then restore the selection if it was set.

Profile
#7
Active user
Points:: 3
Joined:: Sep 16, 2011

Thank you guys!
Escander, the Figure 2 looks like what I need, could you please explain it? I can't get how to reset selections and why CurrentRow will work in that case, while Anatoly says it will not work after DynamicList filters changes.

Profile
#8
Active user
Points:: 1
Joined:: Nov 24, 2011

Code
//common module text(for example MyProcedures)
function IsDinamycListEmpty(ObjectType,ObjectName,DinamycListControl) Export
  QueryBuilder = New QueryBuilder; 
  BuilderText = "SELECT FIRST 1 
  | "+ObjectName+".Ref 
  |FROM 
  | "+ObjectType+".."+ObjectName+".AS "+ObjectName; 
 QueryBuilder.Text = BuilderText; 
 DataSourceDescription = New DataSourceDescription(DinamycListControl); 
 QueryBuilder.DataSource = DataSourceDescription; 

 QueryBuilder.Execute(); 
 QueryTable = QueryBuilder.Result.Unload(); 
 Return ?(QueryTable.Count() > 0,false,true)
EndFunction


//call function examples

if MyProcedures.IsDinamycListEmpty("Catalog","Clients",ClientsList) then
////
endif

if MyProcedures.IsDinamycListEmpty("Document","Invoice",InvoicesList) then
////
endif

I didn't test this :)

Profile
#9
Active user
Points:: 3
Joined:: Sep 16, 2011

Thank you, Anatoly, but to use this method I will have to synchronize the query in the DynamicList and in this additional query. Which I wouldn't like to do... If possible.

Profile
#10
Just came
Points:: 0
Joined:: Nov 23, 2011

Silvia Ashley, tomorrow will try to distribute the sample (already too late).

Profile
#11
Just came
Points:: 0
Joined:: Nov 23, 2011

In the general course in the morning immediately evident that the optimal solution is unique!
Use the query - this is optimal, but more often to check it does not reach.
The code below for a list form catalog customers.

Code
&AtServerNoContext
Function TestOnServer()
   Query = New Query;
   Query.Text = 
      "SELECT TOP 1
      |   Catalog.Ref
      |FROM
      |   Catalog.Контрагенты AS Catalog";
 = Query.Execute();
Return  Result.IsEmpty();
EndFunction



&AtClient
Function ListEmpty()
   ii=True;
   If Lists.Filter.Items.Count()=0 Then
      If ValueIsFilled(Items.List.CurrentRow) Then
         ii=False;
      EndIf;   
   Else   
      If ValueIsFilled(Items.List.CurrentRow) Then
         ii=False;
      Else
         ii=TestOnServer();
      EndIf;   
   EndIf;
Return ii;   
EndFunction


&AtClient
Procedure OnOpen(Cancel)
   ff=ListEmpty();
EndProcedure

Profile
#12
Just came
Points:: 0
Joined:: Nov 23, 2011

Forum engine eats up the code formatting - it looks ugly of course, not that the configuration tool

Profile
#13
Active user
Points:: 3
Joined:: Sep 16, 2011

If someone knows how to get a query which is stored in the DynamicList settings?

Profile
#14
Just came
Points:: 0
Joined:: Nov 23, 2011

Not always DynamicList based on a query can be used and a dynamic read and fill DynamicList with data having no connection to the dat abase(meaning a programmatic).
Get text queries will be a function:

Code
&AtServer
Function QueryFromFormOnServer()
TxtQ="":
If List.CustomQuery Then
  TxtQ=List.QueryText:
EndIf
Return TxtQ;
EndFunction

Profile
#15
Active user
Points:: 3
Joined:: Sep 16, 2011

Thank you, Escander! That is what I need: both getting the query text and adding filters to it do solve my problem.

Profile
#16
Just came
Points:: 0
Joined:: Nov 23, 2011

Glad I could help 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.