Regarding JavaScript with SharePoint 2019 on premise REST API

Will 616 Reputation points
2020-12-03T10:03:09.11+00:00

I use a JavaScript with REST APIs to access backend List for specific purpose to do some limitations in Personal Site. It turns out different result between my Lab with testing environment. I list out my code as the shown below:

There are somewhat different between two environments: 1. Lab - Standalone Machine; 2. Testing - 1* WFE plus 1* Application with WFE;

var raJsEnableOrDisableUrl = _PersonalSiteHostUrl + "/_api/web/lists/getbytitle('PS Configuration')/items?$select=sp_Value&$filter=Title eq 'PS_OD_VERIFY_USER_STATUS'"

and

Testing Environment:

if (_dataJsEnableOrDisable.results[0].sp_Value === "1") -> the sp_Value should be 1 or 0, but <results> length is always 0. That means I cannot get anything from my List.

My Lab : work properly and get 1 record from the List.

Is there anything missing?? or Is environment issue??

44768-2020-12-03-23-14-00.png

js: https://1drv.ms/t/s!AitVMPLIZ4qBigtoN7ocYz6t59lH?e=dC01fA

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-12-04T06:16:20.497+00:00

    I suggest you add "async: false" attribute to GetPersonalSiteHostUrl function, otherwise _PersonalSiteHostUrl will be " " when executed.
    And when I use _PersonalSiteHostUrl = data.d.PersonalSiteHostUrl , the code report error ,I change it to _PersonalSiteHostUrl = data.d.PersonalUrl.
    No matter which one you use, the Url ends with “/”,
    45075-image.png
    you should modify the part of the code you used to splice the URL.

    var raJsEnableOrDisableUrl = _PersonalSiteHostUrl + "_api/web/lists/getbytitle('PS Configuration')/items?$select=sp_Value&$filter=Title eq 'PS_OD_VERIFY_USER_STATUS'";  
        var raJsSCAdminsUrl = _PersonalSiteHostUrl + "_api/web/lists/getbytitle('PS Configuration')/items?$select=sp_Value&$filter=Title eq 'PS_SC_Admins'";  
    

    After I made the above changes to the code and created the corresponding list, it ran successfully.

    45064-image.png
    Full code for your reference:45102-code.txt
    You could use developer tool to debug the code, then you will understand the code running sequence and potential errors, which can help you write better code.
    Debug JavaScript in Chrome


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.