1

I want to get Description value from Hyperlink field in my REST API url and filter using that value. But I am unable to get the value. Below is my Url for REST API

var newsUrl = _spPageContextInfo.webAbsoluteUrl +  "/_api/web/lists/getbytitle('ListName')/Items?$select=ID,Title,HyperlinkCol/Description&$expand=HyperlinkCol&$filter = HyperlinkCol/Description eq 'Approved'";

Any help would be appreciated

Thanks

1

Unfortunately, this looks like a limitation of SharePoint REST API for hyperlink column. Couple of solutions are there which use CAML query which filter on the url value. So that is only possible on the url value not the description of url field.

This is because for 'complex' fields which store multiple values, only the 'default' value is available to query.

This would mean the only way to 'query' like this is to iterate through the items in the list as below.

$.ajax({
    url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('ListName')/items?$select=ID,Title,HyperlinkCol",
    method: "GET",
    headers: { "Accept": "application/json; odata=verbose" },
    success: function (data) {
        if(data.d.results.length>0){
            var items = data.d.results;
            var desc = "";
            //add logic for iteration
            if (items[0].HyperlinkCol) {  
                 desc = items[0].HyperlinkCol.Description;  

                 if(desc == "Approved")
                 {
                    console.log("Approved Item");
                 }
            }
        }
    },
    error: function (data) {
        console.log(data);
    }
}); 

Reference - How do I use REST $filter with a “Hyperlink or Picture” type column?

CAML: Filter URL field on description (not on URL)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.