Multiple Lines of C# Code with

Hi,

I want to use this line of code with Execute C#:

arbeitsberichte.PERSON = getMitarbeitersResult.Where(m => m.loginuser.ToUpperInvariant() == Security.User.Name.ToUpperInvariant()).FirstOrDefault()?.MITARBNR ?? 0.0m;

This does not work, may be because it is C# V6 and this is not supported.

Now I want to put this in more than one line of code in RADZEN editor, but I cannot get this to work. I get an error message during code generation. Is this possible or do I have to write a method in a file which extends the partial class of my page?

Best regards

Frank

Hi @FrankWuttke,

This does not work, may be because it is C# V6 and this is not supported.

What is the error that you are getting? We are using ?. in the code and it compiles fine.

Is this possible or do I have to write a method in a file which extends the partial class of my page?

You can try with a method in the partial class. It should be the cleaner solution.

Hi Atanas,

the error is:

Cannot generate code for "${arbeitsberichte.PERSON = getMitarbeitersResult.Where(m => m.loginuser?.ToUpperInvariant() == Security.User.Name.ToUpperInvariant()).FirstOrDefault().MITARBNR}": Line 1: Unexpected token .. In page: "Add Arbeitsberichte", component: page, event: Load

I have simplyfied it with only one ? to check but as soon as I add the ? I get this error.

Best regards

Frank

Does it work if you remove the ${} from the expression?

Yes, then it works. Cool!

Hi Atanas,

now even my first expression works:

arbeitsberichte.PERSON = getMitarbeitersResult.Where(m => m.loginuser?.ToUpperInvariant() == Security.User.Name.ToUpperInvariant()).FirstOrDefault()?.MITARBNR ?? 0.0m

Thank you very much

Good evening

Frank

Hi @FrankWuttke,

I looked at your question. What I am trying to achieve is very similar. Yet, being at the very beginning of the learning curve, I struggle getting the right syntax. Hopefully you can help.

I have a datagrid with form displaying opportunities. Every time I select an opportunity, I would like a numeric box to return a field value name WeightedAmount from a view called Pipeline and store the value into WeightedCashflow for display, knowing that the opp id is the same than pipeline.id

Within the SelectRow event of the datagrid, I am doing the following:

  • invoking the datasource to assign getPipelinesResult to ${result}
  • Execute C# with weightedcashflow = getPipelinesResult.WeightedAmount.where(m => m.id == ${opp.id});

I get the following error message: 'IEnumerable' does not contain a definition for 'WeightedAmount' and no accessible extension method 'WeightedAmount' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?) [/Users/fr3dk/Documents/Perso/ Salesmetry/Radzen/server/Dashboard.csproj]

Any idea what I do wrong ?

Thank you

Fred

@FredK_Trashmail the compiler error tells it all - the getPipelinesResult property is a collection of Pipelines objects and it doesn't have the properties of the Pipeline itself (WeightedAmount).

Thank you Korchev

I was thinking that the ${result} was containing some sort of image of the table.
From what you said, I understand I should look for a way to access the Pipeline properties directly.
Is there anything I could read to get to the result I am aiming ?

best,

Fred

You need to somehow get a single item from that result. Either use the getXXXById data source method which returns a single record from a table or get an item from the getPipelinesResult property itself. In any case inspecting the code that Radzen generates would help you understand what the data source methods return.

Thank you Korchev,
will try this. On your second suggestion, this is what I try now and then, including the CRM samples, but that's still a stretch for me at this stage.

No success to be honest,

  • Went through all the 6 forum threads where getXXXbyId is mentioned but did not see any example on how this can be defined using the tool,
  • Found some references to it in the Edit Data Items section of the documentation BUT realised it does not seem to apply to Views (I made sure the view was invoked at Page level).

So that doesn't work.

Tried to look at getting to the property itself but likely beyond my ability at this stage.

So I figured out I could:

  1. at the datagrid RowSelect event level, get Pipeline result filtered with id equals ${opp.id}
  2. set a property where FilteredPipeline value is result.First()
  3. assign the numeric box value to the ${filteredpipeline.weightedamount}

No error message but system was hanging and not letting me access the Opportunity page. I thought the filter was causing the issue so removed it. Same hanging
It is a bit surprising because I use this trick of result.First() in other pages (not in a datagrid event though) and it works as expected.

Stuck again

Hi Fred, had no time to respond yet. Presently I am on holidays. When application seems to get stuck, normally an exception happened. Have you tried to open it in visual studio and run it from there? Very often you find more information there what is going on. You can also turn first chance exceptions on in visual studio. This will bring up much more exceptions, that do not matter but it also helps to identify hidden exceptions like type conversion problems or SQL errors.

Frank

Thank you Frank. Will let you know if I still have an issue. Enjoy your holiday

Hi

Issue fixed. It was hanging because on the first time the page is displayed, ${FilteredPipeline.WeightedAmount} is not known as there is no RowSelect event taking place prior to first rendering.

Defining the same Invoke from Data Source and setting FilteredPipeline property at the page level fixed this issue.

Thank you

Fred

1 Like

Hi,

I took a more hardcore approach, following your indication that reloading the grid will not reload the data from the database. Once the record is updated and notified as such, I reload the entire dataset (in the templateForm Submit event), assign the result to ${result} and ask the grid to reload. I imagine this is somehow what happens as part of any Page Load sequence.

Still no luck: the value will change only if I click in the grid.

And still did not understand how to simulate the row click / highlight.

Best regards,

Fred