none
Accessing list or library values from different site colletion to current Site Collection in SharePoint Online RRS feed

  • Question

  • Hi ,

    Can you please provide me different possibilities for the below requirement in SharePoint online.

    I have approximately 10 site collections in that in one site collection i created library or list.

    I want to retrieve the values of that particular list/library into different 9 site collections

    How can we achieve this?

    Thanks

    Thursday, August 22, 2019 6:22 AM

All replies

  • Hi Rajesh,

    The following code snippet for your reference.

    var allSiteResults = [];
    function getSubmissionNo(siteURL, siteCount) {
        if (siteCount < siteURL.length) {
            siteCount++;
            var currentNewUrl;
            for (a = 0; a <= siteURL.length; a++) {
                currentNewUrl = siteURL[a];
                getDataUsingRest(currentNewUrl).then(function (data) {
                    allSiteResults.push(data);
                    getSubmissionNo(siteURL, siteCount);
                }).fail(function (error) {
                    console.log(error);
                })
            }
        }
        else {
            dataReturned(allSiteResults);
        }
    }
    function getDataUsingRest(requiredUrl) {
        var dfd = new $.Deferred;
        $.ajax({
            url: requiredUrl + "/_api/web/lists/getbytitle('E-files')/items?    $select=ImgURL,FileRef&$expand=ContentType&$filter=ContentType eq 'Submission Folder'",
            type: "GET",
            asyn: false,
            headers: {
                "Accept": "application/json;odata=verbose",
            },
            success: function (data) {
                dfd.resolve(data);
            },
            error: function (data) {
                dfd.reject(data);
            }
        });
        return dfd.promise();
    }
    function dataReturned(allSiteResults) {
        $.each(allSiteResults, function (index, data) {
            var k;
            for (k = 0; k < data.d.results.length; k++) {
                var item = data.d.results[k];
                var subN = item.ImgURL;
                var fileRefTest = item.FileRef;
                console.log(fileRefTest);
            }
        })
    }

    Check the similar thread below.

    Get list item data from different site collection using REST api in Javascript

    Or we can use SharePoint Search Query APIs to achieve it.

    function searchTaskItems(webUrl,success, failure) {
        var url = webUrl + "/_api/search/query?querytext='contentclass:STS_ListItem AND ContentType:Task'";
        $.ajax({
            url: url,
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: function (data) {
                success(data.d.query);
            },
            error: function (data) {
                failure(data);
            }
        });
    }
    
    
    //print tasks
    searchTaskItems(_spPageContextInfo.webAbsoluteUrl,
      function(query){
          var resultsCount = query.PrimaryQueryResult.RelevantResults.RowCount;
          for(var i = 0; i < resultsCount;i++) {
              var row = query.PrimaryQueryResult.RelevantResults.Table.Rows.results[i];
              var taskName = row.Cells.results[3].Value;
              console.log(taskName);
          }   
      },
      function(error){
        console.log(JSON.stringify(error));
      }
    );

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, August 23, 2019 1:21 AM
    Moderator
  • Hi Rajesh,

    Any update?

    If my reply help you, please mark the reply as answer, it will make others who stuck with the similar issue easier to search for valid solutions in this forum.

    Best regards,
    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, August 29, 2019 8:27 AM
    Moderator