Home › Forums › vLooup for SharePoint › spjs.utility.addItem with people pickers?
- This topic has 3 replies, 2 voices, and was last updated 4 years, 5 months ago by Alexander Bautz.
-
AuthorPosts
-
-
May 26, 2020 at 17:21 #30280
Hello, I am trying to use the SPJS utility add item and my code is below. In this case I am trying to take a people picker and insert it into the new item. I am getting a syntax error when doing this.
Any thing I need to know about using SPJS utility add item with people pickers?
var associateName = spjs.utility.getFieldValue({"fin":"associateName", "delimiter":"; ", "key":"loginName"}); var listName = "jwUAT"; var nRes = spjs.utility.addItem({ "listName": listName, "data": { "associateName": associateName } }); if (nRes.success) { // item successfully created } else { alert("An error occurred while creating the child item: " + nRes.errorText); }
-
May 26, 2020 at 17:48 #30284
You need to pass the ID of the user (from the userlist in this site collection) – try it like this:
var associateName = spjs.utility.getFieldValue({ "fin": "associateName", "delimiter": "; ", "key": "loginName" }); var user = spjs.utility.userInfo(associateName); if(user.success){ var listName = "jwUAT"; var nRes = spjs.utility.addItem({ "listName": listName, "data": { "associateName": user.ID } }); if (nRes.success) { // item successfully created } else { alert("An error occurred while creating the child item: " + nRes.errorText); } }
Alexander
-
June 3, 2020 at 00:02 #30408
Hi, thank you for that data. This works great for a user that has access to the site, but what about inserting people names that are not currently users of the site?
Use case: creating a list item to assign to Joe Smith. Joe Smith will receive an email from the site, but Joe Smith does not actually use the site as all he needs from it is the email. We have many examples of sites that users do not access them, yet we send communications to them via the sites to call for action on various business processes and tasks.
-
June 3, 2020 at 15:38 #30418
If the person is not an valid user in this site, you cannot use a people picker. You can instead insert the email address in a single line of text field and use that to email the user.
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.