Replies: 2 comments 1 reply
-
@wizofaus : either loading the calculated field by specifying it in the CAML query or by loading via // Query the document again
const string viewXml = @"<View Scope='Recursive'>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='Description' />
<FieldRef Name='calc' />
</ViewFields>
<RowLimit>1</RowLimit>
</View>";
var list = await context.Web.Lists.GetByTitleAsync("calculatedfields");
Expression<Func<IListItem, object>>[] selectors =
{
li => li.All,
li => li.FieldValuesAsText
};
await list.LoadItemsByCamlQueryAsync(new CamlQueryOptions()
{
ViewXml = viewXml,
DatesInUtc = true
}, selectors).ConfigureAwait(false);
Assert.IsTrue(list.Items.AsRequested().First()["Title"].ToString() == "Bert");
Assert.IsTrue(list.Items.AsRequested().First()["Description"].ToString() == "Jansen");
Assert.IsTrue(list.Items.AsRequested().First()["calc"].ToString() == "BertJansen");
Assert.IsTrue(list.Items.AsRequested().First().FieldValuesAsText["calc"].ToString() == "BertJansen"); |
Beta Was this translation helpful? Give feedback.
0 replies
-
FieldValuesAsText definitely didn't give me the values I was looking for when I tried. But still not sure if I need this functionality just yet. Just seemed odd there was no way to add the query parameters that the API can take.
Get Outlook for Android<https://aka.ms/AAb9ysg>
…________________________________
From: Bert Jansen ***@***.***>
Sent: Tuesday, February 20, 2024 8:55:29 PM
To: pnp/pnpcore ***@***.***>
Cc: wizofaus ***@***.***>; Mention ***@***.***>
Subject: Re: [pnp/pnpcore] How to ensure calculated fields are requested using LoadItemsByCamlQuery> (Discussion #1378)
@wizofaus<https://github.com/wizofaus> : either loading the calculated field by specifying it in the CAML query or by loading via FieldValuesAsText works in my test.
// Query the document again
const string viewXml = @"<View Scope='Recursive'>
<ViewFields>
<FieldRef Name='Title' />
<FieldRef Name='Description' />
<FieldRef Name='calc' />
</ViewFields>
<RowLimit>1</RowLimit>
</View>";
var list = await context.Web.Lists.GetByTitleAsync("calculatedfields");
Expression<Func<IListItem, object>>[] selectors =
{
li => li.All,
li => li.FieldValuesAsText
};
await list.LoadItemsByCamlQueryAsync(new CamlQueryOptions()
{
ViewXml = viewXml,
DatesInUtc = true
}, selectors).ConfigureAwait(false);
Assert.IsTrue(list.Items.AsRequested().First()["Title"].ToString() == "Bert");
Assert.IsTrue(list.Items.AsRequested().First()["Description"].ToString() == "Jansen");
Assert.IsTrue(list.Items.AsRequested().First()["calc"].ToString() == "BertJansen");
Assert.IsTrue(list.Items.AsRequested().First().FieldValuesAsText["calc"].ToString() == "BertJansen");
—
Reply to this email directly, view it on GitHub<#1378 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ABI5UALB4GZZ7PVTRTUM7QLYURXJDAVCNFSM6AAAAABCZDBKHOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4DKMRXGYZDA>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The following does nothing (the expression is ignored):
list.LoadItemsByCamlQuery("<View></View>", i => i["LinkFilename"]);
Whereas this throws a 'System.NullReferenceException':
list.LoadItemsByCamlQuery("<View></View>", i => i.QueryProperties(i => i["LinkFilename"]);
But if the field is not explicitly requested, no value for it is returned. This works fine using CSOM (Microsoft.SharePoint.Client library) using the "Include" syntax.
I tried "faking it" by creating a MemberExpression based on an explicitly defined property "LinkFilename" but couldn't get that to work either (the functions for creating Expressions in .NET core do a lot of paranoid type checking, not sure why!). The only thing that actually seemed to (partially) work was to modify the PnP.Core source code to add "LinkFilename" as an actual property of IListItem/ListItem, but obviously that's not workable, as there's no fixed set of possible calculated fields for any SP list.
The other thing that works (but requires access to PnP.Core internals - I did this in the unit test project):
If you don't have access to the internal "ApiCall" property it has to be run via reflection.
I also tried:
But sadly the response is not mapped back to the Items model, so rather defeats the purpose of using the PnP.Core library in the first place (again, I could use ExecuteRequestBatchAsync, and reset the "RawRequest" flag of the ApiCall via reflection, but I'm trying to find a support way of doing this that won't break with future implementation detail changes!).
So how can I explicitly request that this field is loaded?
Beta Was this translation helpful? Give feedback.
All reactions