Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. SharePoint
  4. Problem with pageContext web object, SPFx React

Problem with pageContext web object, SPFx React

Scheduled Pinned Locked Moved SharePoint
sharepointjsonhelpjavascripthtml
1 Posts 1 Posters 11 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ray Fischer
    wrote on last edited by
    #1

    Hello Code-Project Experts, I am trying to call a REST service to add a user to a Sharepoint Group after having him selected using a People Picker. In my SPFx WEBPART, the people picker works just fine but the REST call is not being triggered. I receiving an error of 'Cannot read property 'web' of undefined.' Apparently, the web property of the pageContext object (I need the absoluteURL property to structure my REST call) cannot be assigned over the React component context. Below are the screenshots of the calls from within VS code -

    private addSelectedUsers(): void {
    let currentWebUrl = this.context.pageContext.web.absoluteUrl;
    let requestURL = currentWebUrl.concat("/_api/web/SiteGroups/GetByName('DIN Standard Viewers')/Users");
    console.log(requestURL);
    let dataToPost = JSON.stringify({
    '__metadata': {
    'type': 'SP.User'
    },
    'LoginName': this.state.addUsers
    });
    let spOpts = {
    headers: {
    'Accept': 'application/json;odata=nometadata',
    'Content-type': 'application/json;odata=verbose',
    'odata-version': ''
    },
    body: dataToPost
    };
    this.context.spHttpClient.post(requestURL, SPHttpClient.configurations.v1, spOpts).then((response: SPHttpClientResponse) => {
    if (response.ok) {
    response.json().then((responseJSON) => {
    console.log(responseJSON);
    });
    }
    });
    }

    Here is the code inside my MaintainGroupsProps.ts properties file -

    import { WebPartContext} from '@microsoft/sp-webpart-base';

    export interface IMaintainGroupsProps {
    description: string;
    context: WebPartContext;

    }

    I understand that there was some kind of recent depracation of WebContext. Is this the case? My package JSON version settings for react and react-dom are 16.8.5. I am not at all an expert and appreciate any suggestions you may have. I am teaching myself react and SPFx and this is an exercise for me to better understand the framework. Thanks, everyone. Ray Fischer

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups