Count people in people picker field

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
coresoul
Posts: 23
Joined: Tue Feb 24, 2015

10 Jun 2015

Posted by coresoul - Jun 10 ’15 at 09:46

i have a deue date field in the form which will calculate the due date based on no of approver (peopl picker field) times no of days they have to approve task plus today's date. i have a people picker (multiple value enabled) field and would like to calculate the no of people.

eg. no of people in people picker =3

no of days each approver gets (number field)=2 days

today's date=6/10/2015

Due Date=6/10/2015+3*2

i have a people picker (multiple value enabled) field and would like to calculate the no of people.

how can i achieve this? Please help

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

11 Jun 2015

Hello,


Please use the following code:

Code: Select all

var peopleCount = 0;
//if the people picker is client side rendered
if (fd.field('People').value().constructor == Array)
{
	peopleCount = fd.field('People').value().length;
}
//else it is rendered server side
else
{
	peopleCount = fd.field('People').value().dictionaryEntries.length;
}

var numberOfDaysForApprover = fd.field('NumberOfDaysEachApproverGets').value();
var date = new Date(fd.field('TodaysDate').value());

// if the today's date field is not empty
// this code assumes US date format is being used
if (Boolean(fd.field('TodaysDate').value())) {
	var dateParts = fd.field('TodaysDate').value().split('/');
	var date = new Date(dateParts[2], dateParts[0]-1, dateParts[1]);
	date.setDate(date.getDate() + peopleCount*numberOfDaysForApprover);
	var dueDateString = (date.getMonth()+1) +"/"+date.getDate() +"/" + date.getFullYear();
	fd.field('DueDate').value(dueDateString);
}


Please ask if you have any questions.

coresoul
Posts: 23
Joined: Tue Feb 24, 2015

11 Jun 2015

OMG!! Perfect !!!!! :)

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 21 guests