Count people in people picker field
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
-
rostislavModeratorMember for: 7 years 16 days
Hello,
Please use the following code:
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.
-
coresoulMemberMember for: 7 years 2 months 27 days
OMG!! Perfect !!!!!
Displaying 1 to 2 of 2 messages