Skip to content
This repository has been archived by the owner on Jun 18, 2019. It is now read-only.

Sharepoint 2013 REST API limitations with site columns #178

Closed
mauricionr opened this issue Aug 16, 2016 · 13 comments
Closed

Sharepoint 2013 REST API limitations with site columns #178

mauricionr opened this issue Aug 16, 2016 · 13 comments
Labels

Comments

@mauricionr
Copy link
Contributor

Category

[ ] Enhancement

[ ] Bug

[X ] Question

Expected / Desired Behavior / Question

Suport all kind of field type

Observed Behavior

I'm using PnP-JS-Core and i need get some fields, but according to this link, i can't.
Sharepoint 2013 REST API limitations with site columns

They don't come with the response stuff, in others project's i get then with CSOM, at this time i really will need use CSOM?

I could not find any docs about this _api limitation on MSDN

Thanks!

@patrick-rodgers
Copy link
Contributor

We are targeting REST as much as possible so if there is a gap in the API you can submit a user voice request to let the team know. I haven't looked at this but perhaps there is something we can add to help ease getting these fields in REST - but it looks from that article you linked that we would need to make requests for those fields separately. I am not sure that is the best solution as we wouldn't know what type of fields you really wanted and would be very hard to make generic. Likely the best option is to make the request using the html value as shown for those fields. You could chain the operations together with .then() and aggregate the result on a single object. This is a good candidate for a sample rather than an update to the core library - but open to options.

@mauricionr
Copy link
Contributor Author

@patrick-rodgers it works, i found this columns on FieldValuesAsHtml, Thanks!

@MarkStokes-outlook
Copy link

Does anyone have a code sample for this?

@phillipharding
Copy link

This is a huge ommission from the MS team, after all the REST API can return a Publishing HTML field without a problem, the workaround only works when you're after a single item, if you're looking for a list of items (which includes a Publishing Image column) you're out of luck.

Retrieve Publishing fields using SharePoint 2013 REST

@MarkStokes-outlook
Copy link

MarkStokes-outlook commented May 5, 2017

It really is. I have just sussed it though. Shame as this is a major performance hit.

$pnp.sp.web.lists.getByTitle('Pages').items
.select("Title", "ID", "Country","ArticleStartDate")
.top(4)
.get().then(function(items) {
    for (var i = 0; i < items.length; i++) {
        // variables required to access data in the next promise
        var thisItemID = items[i].ID;
        var thisItemCountry = items[i].Country;
        var thisItemTitle = items[i].Title;
        var thisItemArticleStartDate = items[i].ArticleStartDate;

        $pnp.sp.web.lists.getByTitle('Pages').items.getById(items[i].ID)
        .select("ID", "PublishingRollupImage")
        .fieldValuesAsHTML.get().then(function(itemHTMLFields){
            $("#cs-search-results").append(RedPlane.CaseStudies.displayTemplate.replace("{0}", thisItemID).replace("{1}", itemHTMLFields.PublishingRollupImage).replace("{2}", thisItemCountry).replace("{3}", thisItemTitle).replace("{4}", thisItemArticleStartDate));
        });
    }
});

@mauricionr
Copy link
Contributor Author

I could found the PublishingRollupImage expanding FieldValuesAsText and accessing the propertie FieldValuesAsText.MetaInfo

@phillipharding
Copy link

phillipharding commented May 6, 2017

I've found a way to do this without multiple REST calls, though its a bit schloppy.

First the REST call:
{site url}/_api/web/lists/getbytitle('Pages')/items?$select=Id,Title,FieldValuesAsText/MetaInfo&$expand=FieldValuesAsText

Then to get at the PublishingRollupImage in the response items you have to parse out the MetaInfo field value which contains all field values separated by the \r\n character, each column value is then formatted as {FieldName}:{FieldType}|{FieldValue};

e.g.

PublishingRollupImage:SW|<img alt="" src="/sites/somesite/PublishingImages/Thumbnails/news1.jpg" style="BORDER&#58;0px solid;" />
foreach (item in response.items) {
     var pubImage = (item.MetaInfo || "")
                    .split('\r\n')
                    .filter(function(e) { 
                        return e.match(/^PublishingRollupImage:SW/gi); 
                    } ).map(function(e) { 
                        return e.split('|')[1]; 
                    });
}

@MarkStokes-outlook
Copy link

Awesome stuff. I will try this out myself.

@MarkStokes-outlook
Copy link

I have tried this, but I am not getting the MetaInfo object returned:

$pnp.sp.web.lists.getByTitle('Pages').items
.select("Title", "ID", "Country", "ArticleStartDate","FileRef", "Brands", "CaseStudyCategory", "FieldValuesAsText/MetaInfo")
.filter(RedPlane.CaseStudies.Search.getFilter())
.expand("FieldValuesAsText")
.get().then(function(items) { ... });

@phillipharding
Copy link

Does the REST url PnP creates look correct?

@mauricionr
Copy link
Contributor Author

$pnp.sp.web.lists.getByTitle('Pages').items
.select("Title", "ID", "Country", "ArticleStartDate","FileRef", "Brands", "CaseStudyCategory", "FieldValuesAsText")
.filter(RedPlane.CaseStudies.Search.getFilter())
.expand("FieldValuesAsText")
.get().then(function(items) { ... });

@MarkStokes-outlook try this one!

@emp
Copy link

emp commented May 24, 2017

MetaInfo seems to be pretty heavy the more content you have in each item. If you're building something that's a very average news widget where you just display title, image and some small bit of extra info its probably a bad use case to download its entire PublishingPageContent for example.

I will insist about the omission here mentioned by @phillipharding, if we want to eagerly load these properties just make the API do so already, its been years [wasn't even possible via REST for a long time].

@P3nf0ld
Copy link

P3nf0ld commented Aug 18, 2017

This thread helped me a lot, and eventually enabled me to get the Publishing RollupImage with the FileRef and Title fields I was able to create a news slider..(not exciting I know) anyway heres the complete code for those looking to use pnp.js directly:

$pnp.sp.web.lists.getByTitle("Pages").items.select("Title", "FileRef","fieldValuesAsText/MetaInfo")
  .filter("Title ne 'Page not found'").top(4).orderBy("Modified")
  .expand("fieldValuesAsText").get().then(function (result) {
	for (var i = 0; i < result.length; i++) {           
	  var pubImage = (result[i].FieldValuesAsText.MetaInfo || "")
		.split('\r\n')
		.filter(function(e){return e.match(/^PublishingRollupImage:SW/gi);})
		.map(function(e) {return e.split ('|')[1];});					
		console.log(result[i].Title);
		console.log(result[i].FileRef);
		console.log(pubImage[0]);
	}				 
});

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants