spjs.utility.addItem with people pickers?

Forums vLooup for SharePoint spjs.utility.addItem with people pickers?

Viewing 3 reply threads
  • Author
    Posts
    • #30280
      Jon Whisman
      Participant

      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);
          }
    • #30284
      Alexander Bautz
      Keymaster

      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

    • #30408
      Jon Whisman
      Participant

      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.

    • #30418
      Alexander Bautz
      Keymaster

      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

Viewing 3 reply threads
  • You must be logged in to reply to this topic.