Ref is not defined in Query

For students who study 1C Junior course.

#1
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

I am on 6.Module Task1(Report-Task1-Object manager module).I have a Query and I gave Ref as parameter.There is an error that "Ref" is not defined.
How can I solve this.

Edited: Mesut Kahraman - Oct 09, 2020 06:51 PM
 
#2
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 8
Joined: May 8, 2013
Company: 1C Company

Hi Mesut,

Here is a quote from the task requirements: "Read the Inventory register balance and sort it by the quantity balance in the descending order". It doesn't say anything about reading only some of the balances. It wants you to read all of them.

Edited: Konstantin Rupasov - Oct 13, 2020 10:18 PM
 
#3
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

I also read all of them.
Must I give different Ref in Where condition?

 
#4
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 8
Joined: May 8, 2013
Company: 1C Company

What do you want to use the Ref parameter for, Mesut? Why do you think you need to filter the query results at all?

 
#5
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

I have removed Ref in Where condition and made comment line Query.Parameter.Insert.Error message says "object field not found".I have controlled with debug and I have put a picture about this.

 
#6
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 8
Joined: May 8, 2013
Company: 1C Company

And what is your question, Mesut? This is how the QueryResultSelection object works. Please, watch this episode for more info.

 
#7
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

I have made it(QueryResult) but it is null

 
#8
People who like this:1Yes/0No
Just came
1C:Professional
Rating: 1
Joined: Nov 4, 2018
Company: 1C Innovation VietNam

You encountered "error reading value" because you have not looped through your selection.
A correct approach should be:

Code
Selection=Query.Execute().Select();
   While Selection.Next() Do
      // Selection.ProductDescription -- This will be equal each item description in the Catalogs.Products 
      // Selection.QuantityBalance -- This will be equal to quantity
   EndDo;


Result of the selection debugged is attached below.

P/S: You can also check your result using Query.Execute().Unload()
This will return a value table but should NOT be used for large data because it can slow down the process

 
#9
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

The report what I must do in attachment and my code is below;
İt give error.Please can you help me.


&AtServer
Function YourReport() Export

Template = Reports.TASK1.GetTemplate("YourReport");
Spreadsheet = New SpreadsheetDocument();

// Write your report code here ->

// <-----------------------------

Query=New Query;
Query.Text=
"SELECT
| InventoryBalance.Product AS Product,
| InventoryBalance.QuantityBalance AS QuantityBalance
|FROM
| AccumulationRegister.Inventory.Balance AS InventoryBalance
|
|ORDER BY
| QuantityBalance DESC";

QueryResult=Query.Execute();
Selection=QueryResult.Select();

AreaCaption=Template.GetArea("Caption");
AreaHeader=Template.GetArea("Header");
AreaRecords=Template.GetArea("Records");

Spreadsheet.Clear();

InsertPageBreak=False;
while Selection.Next() do

if  InsertPageBreak then
  Spreadsheet.PutHorizontalPageBreak();
endif;


Spreadsheet.Put(AreaCaption);
Spreadsheet.Put(AreaHeader,Selection.Level());


SelectRecords=Selection.Records.Select();
While SelectRecords.Next() Do
    AreaRecords.Parameters.Fill(SelectRecords);
Spreadsheet.Put(AreaRecords, SelectRecords.Level());
EndDo;

 
Return Spreadsheet;

InsertPageBreak=True;

EndDo;

EndFunction

 
#10
People who like this:0Yes/0No
Active user
1C:Professional
Rating: 8
Joined: May 8, 2013
Company: 1C Company

Hi Mesut,

1. One of the main problems here is that your code is unreadable. This is why you cannot understand what's not working here and why.

You should ALWAYS correctly indent the blocks of code. If you're not sure how to do that, please google it. Here is a good example of an article on the topic.

Please, fix the indentation and tell me to take another look. I'd like to check your indentation and make sure you got it right.

2. The first thing you need to do, when something's not working, is to start DEBUGGING this piece of code. Please, debug this code step by step, checking all the objects down the road, and you will see what's the problem.

 
#11
People who like this:0Yes/0No
Just came
1C:Professional
Rating: 1
Joined: Nov 4, 2018
Company: 1C Innovation VietNam

Hi Mesut,
There are few things to notice which i already commented on your code:
1. Caption and Header area should be put outside of the loop because it is only required to put into spreadsheet once
2. The Pagebreak does not required in the exam
3. The "Selection" already contained all the infomation you need so no need to select twice. Multiple selection is helpful when you use TOTALS BY in query (Hierachy tree)
4. Each area of the template should be input separately
5. Return should be outside of the loop

P/S: You can use Alt+Shift+F shortcut to format indent of all the code.

Code
&AtServer
Function YourReport() Export
   
   Template = Reports.TASK1.GetTemplate("YourReport");
   Spreadsheet = New SpreadsheetDocument();
   
   // Write your report code here ->
   
   Query = New Query;
   Query.Text =
   "SELECT
   |       InventoryBalance.Product AS Product,
   |       InventoryBalance.QuantityBalance AS QuantityBalance
   |FROM
   |       AccumulationRegister.Inventory.Balance AS InventoryBalance
   |
   |ORDER BY
   |       QuantityBalance DESC";
   
   QueryResult = Query.Execute();
   Selection = QueryResult.Select();
   
   // Get Areas
   AreaCaption = Template.GetArea("Caption");
   AreaHeader = Template.GetArea("Header");
   AreaRecords = Template.GetArea("Records");
   
   Spreadsheet.Clear();
   
   // 1. Caption and Header should be outside of the loop
   // because it is only required to put into spreadsheet once
   Spreadsheet.Put(AreaCaption);
   Spreadsheet.Put(AreaHeader); 
   
   //InsertPageBreak = False;
   While Selection.Next() Do
      
      // 2. The Pagebreak does not required in the exam
      //If InsertPageBreak Then
      //   Spreadsheet.PutHorizontalPageBreak();
      //EndIf;
      
      // 3. The "Selection" already contained all the infomation you need
      // Multiple selection is helpful when you use TOTALS BY in query (Hierachy tree)
      // SelectRecords = Selection.Records.Select();
      
      // 4. Each area of the template should be input respectively
      AreaRecords.Parameters.Product = Selection.Product;
      AreaRecords.Parameters.QuantityBalance = Selection.QuantityBalance;
      Spreadsheet.Put(AreaRecords);
                  
      // InsertPageBreak = True;
      
   EndDo;
   
   // 5. Return should be outside of the loop
   Return Spreadsheet;
   
   // <-----------------------------
   
EndFunction

 
#12
People who like this:0Yes/0No
Interested
Rating: 10
Joined: Sep 30, 2020
Company: Nortek Bilişim

I have learned,I shouldn't use SelectRecord in this situation.The problem was solved,Thank you very much!

 
Subscribe
Be the first to know tips & trick 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.