Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using REST and JavaScript to write Multiple People Picker values to ListItem people picker column

Posted on 2016-10-26
8
Medium Priority
?
38 Views
Last Modified: 2016-11-27
I am searching for an example of writing a listitem from a people picker control to a people column of the list.
0
Comment
Question by:Howard Bash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 41893777
do you still need help on this one?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 41893813
could you please do a screen copy of your page or just create a funny photoshop schema, I currenlty don't understand where you want to go.
Thanks
0
 
LVL 1

Author Comment

by:Howard Bash
ID: 41897559
I have figured out/found the techniques for this. Thanks.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 82

Expert Comment

by:leakim971
ID: 41897574
ok, please close the question. if possible after posting your solution and accept it as answer.
0
 
LVL 1

Accepted Solution

by:
Howard Bash earned 0 total points
ID: 41897586
//--------------------------------------------------------------------------------
// Convert People Picker String to JSON Array
//--------------------------------------------------------------------------------
function UserInfoFromPP(ppID) {
	var sObj = $(ppID).val();
	var jObj = null;
	if (sObj.length>0)
	{
		jObj = JSON.parse(sObj);
	}	
	return (jObj);
}


//--------------------------------------------------------------------------------
//  You need to construct a string of the form '{"results":["id1", "id2"]}'
//--------------------------------------------------------------------------------
function BuildPeepsString() {
	var jObj = UserInfoFromPP('#peoplePickerDiv_TopSpan_HiddenInput');
	var acc = '{"results":[';
	var ptr = 0;
	var id = "";
	if (jObj) {
		var len = jObj.length;
		for (ptr=0; ptr<len-1; ptr++) {
			id = GetUserProfileAttribute(jObj[ptr].Key, 'ID');
			acc = acc + '"' + id + '"' + ",";						
		}		
		id = GetUserProfileAttribute(jObj[len-1].Key, 'ID');
		acc = acc + '"' + id + '"' ;						
		acc = acc + ']}';
	}

	return (acc);
}


//--------------------------------------------------------------
function HelpAddPostWithParameters(pp, title, body) {
	//var peeps = '{"results":["9", "21"]}';
	var jsonObject = JSON.parse(pp);
	AddPostWithParameters('Posts', title, body, jsonObject);
}

function AddPostWithParameters(plistName, pTitle, pBody, pPeopleObject) {
	var itemProperties = {"Title":pTitle,"Body": pBody, "PublishedDate":new Date().toISOString(), 	
	"PeopleRecognizedId":  pPeopleObject 
	};
	
	//create item
	createListItem(_spPageContextInfo.webAbsoluteUrl,plistName,itemProperties,
	   function(entity){
		  console.log('Post ' + entity.Title + ' has been added');
	   }, 
	   function(error){
		  console.log(JSON.stringify(error));
	   }
	);	
}

//.... on a submit added the following fragment:
               var comments = $('#txtComments').val();
		var peepsString = "";
		peepsString = BuildPeepsString();  
		var demonstratedValue = $('#hiddenDemonstratedValue').val();
		if (peepsString){		
			HelpAddPostWithParameters(peepsString, demonstratedValue, comments);
		}

Open in new window

2
 
LVL 17

Expert Comment

by:Kyle Santos
ID: 41897821
hbash,

Thank you for posting your solution and closing your question.
0
 
LVL 1

Author Closing Comment

by:Howard Bash
ID: 41902942
It solved the problem.
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question