Passing value from Parent Form to Modal Form in SharePoint 2016

Michael Williams 21 Reputation points
2021-10-26T14:32:58.25+00:00

Hello All,

I found an example to solve my issue, but the problem is that the Line below isn't working. Essentially the SPGetQueryString() isn't working in SharePoint 2016

var queryStringVals = $().SPServices.SPGetQueryString();

https://social.technet.microsoft.com/Forums/azure/en-US/7c58fba7-a095-4dc5-8008-65358edf7886/passing-a-query-string-parameter-to-a-newformaspx-modal-dialog?forum=sharepointdevelopmentprevious

$(document).ready(function() {

//Gets the supplierID from the URL
var queryStringVals = $().SPServices.SPGetQueryString();
var supplierID = queryStringVals["FilterValue1"];

//replaces the onlick attribute of the add new item link with a NewForm.aspx and my query string variable
var incidentHrefandSupplierID = "http://sp2010/sites/MySite/Lists/MyList/NewForm.aspx?SupplierID=" + supplierID;

//console.log(incidentHrefandSupplierID);
$('#WebPartWPQ10 #idHomePageNewItem').attr('href', '#');
$('#WebPartWPQ10 #idHomePageNewItem').attr('onclick', function () {
return "javascript:showDialog('" + incidentHrefandSupplierID + "');"

//console.log(this.onclick); });
});

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,615 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. RaytheonXie_MSFT 30,186 Reputation points Microsoft Vendor
    2021-10-27T07:33:20.45+00:00

    Hi @Michael Williams ,
    Please try to add jquery.min.js and jquery.SPServices-2014.02.min.js into a document library, then reference the files.

    And add try...catch into your code.

    try {  
      adddlert("Welcome guest!");  
    }  
    catch(err) {  
      document.getElementById("demo").innerHTML = err.message;  
    }  
    

    For sharepoint 2016, I will recommend REST API to achieve your requirement
    https://social.technet.microsoft.com/wiki/contents/articles/31995.sharepoint-2013-working-with-rest-api-using-jquery-ajax.aspx


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.



  2. Michael Williams 21 Reputation points
    2021-10-29T13:56:37.38+00:00

    Thank you RaytheonXie-MSFT, I will try the solution later next week and get back with you.

    Michael


  3. Michael Williams 21 Reputation points
    2021-11-02T02:11:44.683+00:00

    I'm sure I already added the correct files, but I'll confirm at work tomorrow.

    Thank You,

    Michael Williams