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.
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.
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.
Rating:
0
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
SelectRecords=Selection.Records.Select(); While SelectRecords.Next() Do AreaRecords.Parameters.Fill(SelectRecords); Spreadsheet.Put(AreaRecords, SelectRecords.Level()); EndDo;
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.
Rating:
0
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