Overnight, with the help of this forum, I figured out how to save a parameter passed via a query string to my Sharepoint api call for "Name" field. I'd like to take this one step further, and instead of saving "Name", I want to save the "Id" that corresponds to the "Name". I know that "Name" is a Lookup field in my list.
The line of code I'm struggling with is this:
var siteIdFromParameter = getSiteParam('Site', _spPageContextInfo.webAbsoluteUrl)?$Id="/_api/web/lists(guid'<guid>')"
Here's all my code:
function getSiteVars() {
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
function getSiteParam(parameter, defaultvalue){
var siteparameter = defaultvalue;
if(window.location.href.indexOf(parameter) > -1){
siteparameter = getSiteVars()[parameter];
}
return getSiteParam;
}
function addFeatureSuggestion() {
var siteNameFromParameter = getSiteParam('Site', _spPageContextInfo.webAbsoluteUrl);
var siteIdFromParameter = getSiteParam('Site', _spPageContextInfo.webAbsoluteUrl)?$Id="/_api/web/lists(guid'<guid>')"
var item = {
"__metadata": { "type": "SP.Data.AddListItem" },
"SiteId": siteIdFromParameter,
"Title": $('#inputTitle').val()
};