Deployed web part is showing errors in console but not for non-local workbench

%3CLINGO-SUB%20id%3D%22lingo-sub-1039437%22%20slang%3D%22en-US%22%3EDeployed%20web%20part%20is%20showing%20errors%20in%20console%20but%20not%20for%20non-local%20workbench%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1039437%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20deployed%20a%20web%20part%20to%20a%20site%20collection%20(where%20the%20web%20part%20is%20designed%20to%20go)%20and%20I%20am%20getting%20errors%20for%203%20particular%20features%20on%20the%20form.%20I%20am%20using%20sp.web%20for%20these%20features.%3C%2FP%3E%3COL%3E%3CLI%3EI%20have%20created%20a%20'Hello%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3EUser%3C%2FEM%3E'%20which%20uses%20this%20function%3A%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epublic%20_getUser()%20%7B%20%0A%20%20%20%20sp.web.currentUser.get().then((user)%20%3D%26gt%3B%20%7B%0A%0A%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20CurrentUserTitle%3A%20user.Title%2C%0A%20%20%20%20%20%20%20%20FullName%3A%20user.Title%2C%0A%20%20%20%20%20%20%20%20CurrentUser%3A%20user.LoginName%2C%0A%20%20%20%20%20%20%20%20CurrentUserID%3A%20user.Id%2C%0A%20%20%20%20%20%20%20%20CurrentUserEmail%3A%20user.Email%2C%0A%0A%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E2.%20A%20Departments%20list%20drop%20down%20which%20populates%20with%20an%20SP%20list%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Epublic%20_getDepartments()%20%7B%0A%20%20sp.web.lists.getByTitle(%22Departments%22).items.get().then((items%3A%20any%5B%5D)%20%3D%26gt%3B%20%7B%0A%20%20%20%20let%20returnedDepts%3A%20IDropdownOption%5B%5D%20%3D%20items.map((item)%20%3D%26gt%3B%20%7B%20return%20%7B%20key%3A%20item.Title%2C%20text%3A%20item.Title%20%7D%3B%20%7D)%3B%0A%20%20%20%20this.setState(%7B%20DepartmentsList%3A%20returnedDepts%20%7D)%3B%0A%20%20%7D)%3B%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E3.%20A%20Submit%20button.%20The%20function%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Eprivate%20_onSubmit()%20%7B%0A%0A%20%20%20%20%20%20sp.web.lists.getByTitle('Data%20and%20Report%20Form').items.add(%7B%0A%0A%20%20%20%20%20%20%20%20FullName%3A%20this.state.FullName%2C%0A%20%20%20%20%20%20%20%20UniId%3A%20this.state.UniId%2C%0A%20%20%20%20%20%20%20%20Email%3A%20this.state.UserEmail%2C%0A%20%20%20%20%20%20%20%20Phone%3A%20this.state.PhoneNo%2C%0A%20%20%20%20%20%20%20%20Department%3A%20this.state.SelectedDept%2C%0A%20%20%20%20%20%20%20%20SubDepartment%3A%20this.state.SubDepartment%2C%0A%20%20%20%20%20%20%20%20StartDate%3A%20this.state.StartDate%2C%0A%20%20%20%20%20%20%20%20DiscoveryDate%3A%20this.state.DateOfDiscovery%2C%0A%20%20%20%20%20%20%20%20Details%3A%20this.state.IncidentDetails%2C%0A%20%20%20%20%20%20%20%20PersonalData%3A%20this.state.PersonalData%0A%0A%20%20%20%20%20%20%7D).then((iar%3A%20ItemAddResult)%20%3D%26gt%3B%20%7B%0A%20%20%20%20%20%20%20%20console.log(iar)%3B%0A%20%20%20%20%20%20%20%20let%20list%20%3D%20sp.web.lists.getByTitle('Data%20and%20Report%20Form')%3B%0A%20%20%20%20%20%20%20%20list.items.getById(iar.data.Id).update(%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20Title%3A%20'DIBR'%2Biar.data.Id%2C%20%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20this.setState(%7B%0A%20%20%20%20%20%20%20%20%20%20JobRef%3A%20iar.data.Id%2C%0A%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20form%20works%20perfectly%20in%20non-local%20SharePoint%20workbench%20served%20on%20the%20actual%20site%20it's%20meant%20to%20be%20deployed%20on.%20When%20deployed%20as%20a%20package%20to%20the%20site%20itself%20and%20added%20as%20a%20web%20part%20it%20now%20shows%20these%20errors%3A%3C%2FP%3E%3CP%3EHTTP404%3A%20NOT%20FOUND%20-%20The%20server%20has%20not%20found%20anything%20matching%20the%20requested%20URI%20(Uniform%20Resource%20Identifier).%20(Fetch)GET%20-%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmydomain.sharepoint.com%2Fsites%2FIncidentReporting%2FSitePages%2F_api%2Fweb%2Fcurrentuser%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FmyDomain.sharepoint.com%2Fsites%2FIncidentReporting%2FSitePages%2F_api%2Fweb%2Fcurrentuser%3C%2FA%3E%3C%2FP%3E%3CP%3EHTTP404%3A%20NOT%20FOUND%20-%20The%20server%20has%20not%20found%20anything%20matching%20the%20requested%20URI%20(Uniform%20Resource%20Identifier).%20(Fetch)GET%20-%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmydomain.sharepoint.com%2Fsites%2FIncidentReporting%2FSitePages%2F_api%2Fweb%2Flists%2FgetByTitle%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FmyDomain.sharepoint.com%2Fsites%2FIncidentReporting%2FSitePages%2F_api%2Fweb%2Flists%2FgetByTitle%3C%2FA%3E('Departments')%2Fitems%3C%2FP%3E%3CP%3EI%20get%20a%20similar%20message%20when%20trying%20to%20submit.%20A%20I%20said%2C%20these%20all%20work%20on%20the%20non-local%20workbench.%3C%2FP%3E%3CP%3EAdditional%20details%3A%3C%2FP%3E%3CP%3EIf%20I%20add%20the%20webpart%20to%20the%20homepage%20of%20the%20modern%20site%20as%20a%20web%20part%20I%20get%20these%20error%20(different%20to%20the%20ones%20if%20I%20add%20the%20webpart%20to%20a%20page)%3A%3C%2FP%3E%3CP%3EHTTP404%3A%20NOT%20FOUND%20-%20The%20server%20has%20not%20found%20anything%20matching%20the%20requested%20URI%20(Uniform%20Resource%20Identifier).%20(Fetch)GET%20-%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmydomain.sharepoint.com%2Fsites%2F_api%2Fweb%2Flists%2FgetByTitle%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FMyDomain.sharepoint.com%2Fsites%2F_api%2Fweb%2Flists%2FgetByTitle%3C%2FA%3E('Departments')%2Fitems%3C%2FP%3E%3CP%3EHTTP404%3A%20NOT%20FOUND%20-%20The%20server%20has%20not%20found%20anything%20matching%20the%20requested%20URI%20(Uniform%20Resource%20Identifier).%20(Fetch)GET%20-%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fmydomain.sharepoint.com%2Fsites%2F_api%2Fweb%2Fcurrentuser%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FMyDomain.sharepoint.com%2Fsites%2F_api%2Fweb%2Fcurrentuser%3C%2FA%3E%3C%2FP%3E%3CP%3Eas%20you%20can%20see%20it's%20missing%20the%20actual%20site%20in%20the%20URL.%20Why%20the%20difference%3F%3C%2FP%3E%3CP%3EHas%20anyone%20got%20an%20idea%20why%20it's%20behaving%20differently%20when%20deployed%3F%20And%20why%20is%20it%20showing%20a%20different%20error%20if%20I%20place%20the%20web%20part%20on%20different%20areas%20of%20the%20site%20collection.%3C%2FP%3E%3CP%3ET%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Contributor

I have deployed a web part to a site collection (where the web part is designed to go) and I am getting errors for 3 particular features on the form. I am using sp.web for these features.

  1. I have created a 'Hello User' which uses this function:

 

public _getUser() { 
    sp.web.currentUser.get().then((user) => {

      this.setState({
        CurrentUserTitle: user.Title,
        FullName: user.Title,
        CurrentUser: user.LoginName,
        CurrentUserID: user.Id,
        CurrentUserEmail: user.Email,

      }

 

 

2. A Departments list drop down which populates with an SP list:

 

 

public _getDepartments() {
  sp.web.lists.getByTitle("Departments").items.get().then((items: any[]) => {
    let returnedDepts: IDropdownOption[] = items.map((item) => { return { key: item.Title, text: item.Title }; });
    this.setState({ DepartmentsList: returnedDepts });
  });
}

 

 

3. A Submit button. The function:

 

 

private _onSubmit() {

      sp.web.lists.getByTitle('Data and Report Form').items.add({

        FullName: this.state.FullName,
        UniId: this.state.UniId,
        Email: this.state.UserEmail,
        Phone: this.state.PhoneNo,
        Department: this.state.SelectedDept,
        SubDepartment: this.state.SubDepartment,
        StartDate: this.state.StartDate,
        DiscoveryDate: this.state.DateOfDiscovery,
        Details: this.state.IncidentDetails,
        PersonalData: this.state.PersonalData

      }).then((iar: ItemAddResult) => {
        console.log(iar);
        let list = sp.web.lists.getByTitle('Data and Report Form');
        list.items.getById(iar.data.Id).update({
            Title: 'DIBR'+iar.data.Id, 
        });
        this.setState({
          JobRef: iar.data.Id,
        });
      });
    }

 

The form works perfectly in non-local SharePoint workbench served on the actual site it's meant to be deployed on. When deployed as a package to the site itself and added as a web part it now shows these errors:

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). (Fetch)GET - https://myDomain.sharepoint.com/sites/IncidentReporting/SitePages/_api/web/currentuser

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). (Fetch)GET - https://myDomain.sharepoint.com/sites/IncidentReporting/SitePages/_api/web/lists/getByTitle('Departments')/items

I get a similar message when trying to submit. A I said, these all work on the non-local workbench.

Additional details:

If I add the webpart to the homepage of the modern site as a web part I get these error (different to the ones if I add the webpart to a page):

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). (Fetch)GET - https://MyDomain.sharepoint.com/sites/_api/web/lists/getByTitle('Departments')/items

HTTP404: NOT FOUND - The server has not found anything matching the requested URI (Uniform Resource Identifier). (Fetch)GET - https://MyDomain.sharepoint.com/sites/_api/web/currentuser

as you can see it's missing the actual site in the URL. Why the difference?

Has anyone got an idea why it's behaving differently when deployed? And why is it showing a different error if I place the web part on different areas of the site collection.

T

 

 

 

0 Replies