0

Set up:
Something that may be relevant is that the Sharepoint is in spanish.
The script accesses a list to know if the current user has read the mandatory information. This list has a reader field and a objectToRead field, first a person, second a lookup that references SitePages.

My objective:
Getting the URL to the site from the lookup field with JS.

Preferably with one call to the API.

What I have:
Imports:

import * as React from "react";
import {sp} from "@pnp/sp";
import styles from "./AppCustomizer.module.scss";
import { ITopUnreadListProps } from "./Iface/ITopUnreadListProps";
import { ITopUnreadListState } from "./Iface/ITopUnreadListState";

At the end of the constructor of the React app I call the following function, which changes the state an it updates the app:
(The following code does not give errors)

private async obtainRemainingMandatoryRead () : Promise<void>
    {
        const shpList = sp.site.rootWeb.lists.getByTitle('mandatoryReadList');
        const currentUser : string=  this.props.ShpContext.pageContext.user.displayName;
        const filter = "(reader/Title eq '"+ currentUser +"') and (isRead eq false)";


        shpList.items
        .select("Title", "reader/Id,reader/Title", "objectToRead/Title,objectToRead/Id") // Can I get the URL here?
        .expand("reader", "pageToRead")
        .filter(filter)
        .get()
        .then
        (
            (row) => {
                //console.log(row);
                let count = row.length;
                let items = row.map( (item) => { return { Title: item.pageToRead.Title}; } );

                if(count > 3)
                {
                    items = items.slice(0, 3);
                }
                this.setState( {list: items, itemCount: count} );
            }
        );
    }

Is it possible to get the URL in with the select? Is there a naming wiki somewhere to know the field's names in the Rest API?

I have been trying with different names like FileRef, link, myLink, url, pageUrl, Path...(not even Name works) And searched for anything that could help. My alternative right now is to make a second call to the API.

The error that it gives (in spanish) is the following:

Uncaught (in promise) Error: Error making HttpClient request in queryable [400] ::> {"odata.error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"es-ES","value":"La consulta realizada al campo 'objeto/Name' no es v\u00e1lida."}}}

(The query made to the field 'objectToRead/{WhateverItryToGetTheLink}' is not valid)

I have already seen this post:
Get File Url from a Lookup Column REST API

But those fields are not working for me.

Your Answer

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

Browse other questions tagged or ask your own question.