Skip to content
Advertisement

Contents of a folder (retrieved via stored procedure) not loading onto page

I’m running a stored procedure in order to get the contents of a folder and display them on a page. When I run the procedure I can see all of the documents that are in the folder, but on the page itself the contents aren’t appearing

I’m able to load the contents of other folders on the page without issue, so I don’t know what’s going on with this particular “weird folder” that’s preventing the content from loading.

Here’s a screencap of the stored procedure (redacted info) from SQL Server Mgmt Studio. The person who created the folder’s name is hidden at the top of the page, in purple. Row 21 is the folder and Rows 1-20 are its contents.

And here’s a screencap of what my devtools looks like.

JS:

import axios from "axios";

let permissionToCallAPI;

export default class {
  constructor() {
    this.setTokenVar();
    this.detectIsPageAdmin();

    this.getCurrentUser(() => {
        this.loadModalTable("#tableModal", 402764); // this is the ID of the folder
    });

 setTokenVar() {...}

 detectIsPageAdmin() {...}

 loadModalTable(table, docNumber, _level) {

    const postTableURL = _RestHostURL + "/Query/Post";

    _level = _level ? _level : 0;
    $.support.cors = true;

    permissionToCallAPI.then(function(_token) {
    axios.post(
        postTableURL,
        {
            Key: "3",
            Procedure: "usp_GetChildFolders", // stored procedure
            Params: {
                DocNumber: docNumber,
                SAMAcct: sessionStorage.getItem("samacct"),
                OnlyFolders: "0" 
            }
        },
        {
            withCredentials: true,
            headers: {
                "Accept": "application/json; odata=verbose",
                "content-type": "application/json",
                "Authorization": _token
            }
        }           
    )
    .then(function(response) {
        const results = response.data; // console.log(results) is empty

        if ($(table + " .head").length <= 0) {
            let divHead = document.createElement("div");
            // in this block, the table header is created
        }
        $(table + " > .body").remove();

        $.each(results, function(indx, obj) {
            let divBody = document.createElement("div");
                divBody.className = "body row";
                $(divBody).attr("parent", obj.ParentID);
                $(divBody).attr("docnumber", obj.DocumentNumber);
                $(divBody).attr("isfolder", obj.IsFolder);
                $(divBody).attr("level", parseInt(_level) + 1);

                if (indx % 2 == 1) $(divBody).addClass("alt");

            if (obj.IsFolder) {
                $(divBody).append(
                    // folder icon
                );
            } else {
                $(divBody).append(
                    // file extension icon
                );
            }
            $(divBody).append(
                "<div class='col-2'>" + obj.DocumentNumber + "</div>"
            );
            $(divBody).append(
                "<div class='col-8'>" + obj.DisplayField + "</div>"
            );
            $(table).append(divBody);
        });

        })
        .catch((error) => {
            console.error(error);
        });
     });
}

Advertisement

Answer

I did some digging and found an answer: In the line SAMAcct: sessionStorage.getItem("samacct"), I was passing in my own credentials instead of the person who created the folder. As such, I couldn’t see the folder contents.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement