nI3o
December 16, 2019, 9:56am
1
Hey There,
So the idea is, that the user selects items in a list/libary and then clicks a button("add to parent"), JavaScript then populates the "parent_id" field with the ID of the currently opend item.
I got the Button, but i couldnt find anything on how to change the values.
click: function() {
var itemIds = fd.control('SPDataTable2').selectedItems);
console.log(itemIds)
;}}
Greetings from Germany
Nico
Hello @nI3o .
You need to use PnPjs to update items in another list. Please see the code example below.
Note that you need to add Id after the internal name of the lookup field.
For more information, please see PnPjs documentation on working with SharePoint items .
var parentItemId = fd.itemId;
var table =fd.control('SPDataTable0').selectedItems;
if(table.length != 0){
for (var i = 0; i < table.length; i++){
var childItemId = table[i].ID;
sp.web.lists.getByTitle("ChildListName").items.getById(childItemId).update({
LookupFieldNameId: parentItemId
}).then(function() {
console.log("Updated!");
});
}
}
nI3o
December 17, 2019, 10:00am
3
Hey @mnikitina
thanks alot, works perfectly and the docu helps alot.
One more thing
Whats the syntax for deleting the id value, couldnt find it
@nI3o ,
Do you mean clearing the lookup value in the child list?
If so, the code will be the following:
var childItemId = table[i].ID;
sp.web.lists.getByTitle("ChildListName").items.getById(childItemId).update({
LookupFieldNameId: null
}).then(function() {
console.log("Updated!");
});
nI3o
December 18, 2019, 8:32am
5
Could have figured that out by myself thanks
1 Like