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
R

Ray Fischer

@Ray Fischer
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Problem with pageContext web object, SPFx React
    R Ray Fischer

    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

    SharePoint sharepoint json help javascript html
  • Login

  • Don't have an account? Register

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