I have two lists 'a' and 'b' with same titles but different ids. I retrieve the title from 'a' list to a html page. And, there is a 'b' list. Here, both the lists have different ids but has same titles (same items). I have created a variable count to increment the count value in Count column in b list. Now my idea is to update the count value of that clicked item from the html page in the 'b' list. Any solutions/ suggestions or help from you would be greatly appreciated!
Retrieving the title from 'a' list to a html page:
function xyz() {
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('a')/items?$top=1000";
$.ajax({
url: resturl,
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
var lnt = data.d.results.length;
var name = "";
var cntlnks = "";
var iconurl = "";
for (var i = 0; i < lnt; i++) {
if (data.d.results[i].Title == "MGT") {
name = data.d.results[i].Name;
itemid = data.d.results[i].ID;
cntlnks = data.d.results[i].ContentLinks;
iconurl = data.d.results[i].Iconurl;
if (data.d.results[i].Phasenumber == 1) {
if (data.d.results[i].Phasegroup == "g") {
$("#mgd1").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems" ><a href=' + cntlnks + ' target="_blank" onclick="myFunc(this);" value="' + name + ' ' + itemid + '">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "t") {
$("#mgt1").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "s") {
$("#mgs1").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
}
if (data.d.results[i].Phasenumber == 2) {
if (data.d.results[i].Phasegroup == "g") {
$("#mgd2").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "t") {
$("#mgt2").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "s") {
$("#mgs2").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
}
if (data.d.results[i].Phasenumber == 3) {
if (data.d.results[i].Phasegroup == "g") {
$("#mgd3").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "t") {
$("#mgt3").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
if (data.d.results[i].Phasegroup == "s") {
$("#mgs3").append('<div class="rowAlign"><img src= ' + iconurl + ' class="groupingIcon" /><p class="listedItems"><a href=' + cntlnks + ' target="_blank">' + name + '</a></p></div></ br>')
}
}
}
}
},
error: function (data) {
console.log(data.responseJSON.error);
}
});
}
function myFunc(lnk) {
let val = lnk.getAttribute('value');
console.log(val);
updateItems(val);
}
Updating list item count value in b list:
var count = 0;
function updateItems() {
count = count + 1;
var resturl = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('b')/getItemById(1)";
var itemType = GetItemTypeForListName('b');
$.ajax({
url: resturl,
type: "POST",
data: JSON.stringify({'__metadata': { 'type': itemType }, 'Count': count }),
headers: {
"accept":"application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest":$("#__REQUESTDIGEST").val(),
"X-HTTP-Method": "MERGE",
"IF-MATCH":"*"
},
success: onSuccess,
error: onError
});
function onSuccess(data) {
alert('List Item Updated');
}
function onError(error) {
alert(JSON.stringify(error));
}
function GetItemTypeForListName(name) {
return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";
}
}
b
matches theName
field from lista
? Is there also aName
field in listb
, or doesName
from lista
match theTitle
field in listb
?<a>
link to actually go to thehref
URL (ContentLinks
)?