How to find out if the dynamic list is not empty?

The 1C:Enterprise developers forum

#1
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

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.

 
#2
People who like this:0Yes/0No
Just came
Rating: 0
Joined: Nov 23, 2011
Company:

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)

 
#3
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

:( 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?

 
#4
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company:

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

 
#5
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Nov 24, 2011
Company:

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

 
#6
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

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.

 
#7
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

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.

 
#8
People who like this:0Yes/0No
Active user
Rating: 2
Joined: Nov 24, 2011
Company:

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

 
#9
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

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.

 
#10
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

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

 
#11
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

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

 
#12
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

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

 
#13
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

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

 
#14
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

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

 
#15
People who like this:0Yes/0No
Active user
Rating: 6
Joined: Sep 16, 2011
Company: TLG Integration

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

 
#16
People who like this:0Yes/0No
Just came
Rating: 1
Joined: Nov 23, 2011
Company:

Glad I could help you

 
Subscribe
Users browsing this topic (guests: 1, registered: 0, hidden: 0)
Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.