Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Manage Allow Multiple Selection in Task List Assigned to Field using JSOM
WhatsApp
Kaviya Balasubramanian
9y
5.3
k
0
1
25
Blog
Implementation:
Declare the public variables.
Get Host Web URL and App web URL in Document Ready.
Then call
MakeMultiSelectionToUserField
method.
Get app context site from
AddEnterpriseColumnToList
method.
Get web and Task list.
Get assigned to filed by Internal name.
Then case to the assigned to field to user field.
Set Allow multiple values to True.
Load the user Field.
Execute the request.
Show result in success method.
Failure method are used to catch the errors.
//Varibles Declaration
var appWebURL, hostWebURL, appCtxSite, context;
// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
hostWebURL = decodeURIComponent(manageQueryStringParameter(
'SPHostUrl'
));
appWebURL = decodeURIComponent(manageQueryStringParameter(
'SPAppWebUrl'
));
MakeMultiSelectionToUserField();
});
//Make assigned to field accept multivalues
function MakeMultiSelectionToUserField() {
hostWebURL = decodeURIComponent(manageQueryStringParameter(
'SPHostUrl'
));
appWebURL = decodeURIComponent(manageQueryStringParameter(
'SPAppWebUrl'
))
var context =
new
SP.ClientContext(appWebURL);
var appCtxSite =
new
SP.AppContextSite(context, hostWebURL);
//get Web
var web = appCtxSite.get_web();
//Get list by title
var list = web.get_lists().getByTitle(
'Tasks'
);
//Get assigned to by internal name
var field = list.get_fields().getByInternalNameOrTitle(
"AssignedTo"
);
var userField = context.castTo(field, SP.FieldUser);
//Manage allow multiple values for assigned to column
userField.set_allowMultipleValues(
true
);
userField.update();
context.load(userField);
context.executeQueryAsync(function () {
//Success Method
alert(userField.get_allowMultipleValues());
console.log(
"Field added successfully!!"
+ field);
}
, function (sender, args) {
//Failure method Method
console.log(
"Request failed"
+ args.get_message());
});
}
//Getting host web url and app web url from query string using this method
function manageQueryStringParameter(paramToRetrieve) {
var
params
= document.URL.split(
"?"
)[1].split(
"&"
);
var strParams =
""
;
for
(var i = 0; i <
params
.length; i = i + 1) {
var singleParam =
params
[i].split(
"="
);
if
(singleParam[0] == paramToRetrieve) {
return
singleParam[1];
}
}
}
Summary
In this blog, we have explored how to allow multiple selection users in SharePoint task list assigned to field using JavaScript Object model. I hope above explained solution is very useful to you. Happy Coding!
Manage Allow Multiple Selection in Task List Assigned to Field using JSOM
Up Next
How To Assign Task To User And Send Approval Using Workflow In SharePoint Online
Ebook Download
View all
SharePoint Framework (SPFx) A Developers Guide
Read by 11.1k people
Download Now!
Learn
View all
Membership not found