Page 1 of 1

Count people in people picker field

Posted: 10 Jun 2015
by coresoul
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

Re: Count people in people picker field

Posted: 11 Jun 2015
by rostislav
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.

Re: Count people in people picker field

Posted: 11 Jun 2015
by coresoul
OMG!! Perfect !!!!! :)