Page 1 of 1

Converting Business Object

Posted: Fri Oct 25, 2024 8:15 am
by admin@secsol.co.uk
HI,

I have a BusinessObject in my data sources and in a user defined function (C#) I am trying to convert the business object back to its original type using this code :

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.EstimateSection> FullSectionList = SelectedEstimate.FullSectionList as System.Collections.ObjectModel.Collection<Cypher1.EstimateSection>;
but I get the following error saying that the BusinessObject cannot be converted to a Collection<>
The error of compilation is found in the 'Schedule Of Rates Detailed' report: Compilation error: Cannot convert type 'Reports.Report.SelectedEstimateBusinessObject.FullSectionListBusinessObject' to 'System.Collections.ObjectModel.Collection' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
What have I done wrong?

Re: Converting Business Object

Posted: Fri Oct 25, 2024 9:32 pm
by Lech Kulikowski
Hello,

Please send us a sample that reproduces the issue for analysis.

Thank you.

Re: Converting Business Object

Posted: Sun Oct 27, 2024 9:00 pm
by admin@secsol.co.uk
Hi, I have attached a sample project that shows the problem.

If you run the program and load the Report.mrt file then click the Preview you will see the error.

Re: Converting Business Object

Posted: Mon Oct 28, 2024 2:02 pm
by Max Shamanov
Hello,

We require more time to investigate the issue thoroughly.

Thank you.
#15849

Re: Converting Business Object

Posted: Fri Nov 01, 2024 7:45 am
by Max Shamanov
Hello,

Please use the following code for a custom function:

Code: Select all

TestItem SelectedItem = null;

System.Collections.ObjectModel.Collection<TestItem> TestItemList = TestList.Current as System.Collections.ObjectModel.Collection<TestItem>;

foreach(TestItem TItem in TestItemList)
{
  if(TItem.Recno == recno)
  {
    SelectedItem = TItem;
    break;
  }
}

return SelectedItem;
Thank you.

Re: Converting Business Object

Posted: Mon Nov 04, 2024 9:14 pm
by admin@secsol.co.uk
Thank you, that works perfectly.

Re: Converting Business Object

Posted: Tue Nov 05, 2024 5:55 am
by Max Shamanov
Hello,

You are Welcome!