Pnpjs: getItemsByCAMLQuery not returning people field Expand value

Created on 10 May 2019  路  4Comments  路  Source: pnp/pnpjs

Hi,
I am trying to expand People picker field by using getItemsByCAMLQuery. Unfortunately I am not getting expanded value. Below is the code I use to expand person field - k_submitter

image

`const q: CamlQuery = {
ViewXml: xml
};

pnp.sp.web.lists
.getByTitle("MyList")
.getItemsByCAMLQuery(q, "k_submitter/Title")
.then((items: any[]) => {
console.log("items", items);
});`

image

my pnp version -> @pnp/pnpjs": "^1.3.0"
Any help on this is highly appreciated. Thank you in advance.

Most helpful comment

Not sure that such a mixture of CAML+OData would ever work this way.
You can use pure OData .select('Person/Title').expand('Person') or expanding FieldValuesAsText in getItemsByCAMLQuery or trying renderListDataAsStream which also deals with CAML but offers more options.

1. getItemsByCAMLQuery and expanding FieldValuesAsText:

image

2. renderListDataAsStream:

image

All 4 comments

Not sure that such a mixture of CAML+OData would ever work this way.
You can use pure OData .select('Person/Title').expand('Person') or expanding FieldValuesAsText in getItemsByCAMLQuery or trying renderListDataAsStream which also deals with CAML but offers more options.

1. getItemsByCAMLQuery and expanding FieldValuesAsText:

image

2. renderListDataAsStream:

image

Thank you @koltyakov , yes it is helpful and now I can get the Text value of people picker field. But the internal name of the field is different, any idea why?.

image

And I was referring to this https://github.com/SharePoint/PnP-JS-Core/issues/777#issuecomment-380446030 so that I used CAML query with field/Title expand option. Unfortunately I didn't get expected output.

SharePoint & REST API as well replaces special characters. What you're dealing is even not internal names but OData entity properties names. In most of the cases, EntityPropertyName is equal to Internal name but not always (k_submitter would have the same Internal and Entity names). In expanded FieldValues* some additional replacements are taking place as _ replacement with its Unicode representation _x005f_. Interesting, I even didn't pay attention to this as almost never use getItemsByCAMLQuery. Anyways it's on the API's side, not the library's.

Thank you again @koltyakov its really informative. Going to close this ticket since you resolved the issue.

Was this page helpful?
0 / 5 - 0 ratings