TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gowtham
NA
516
40.7k
How to site column to content type using js
Mar 2 2017 9:23 AM
So for I have tried.The code which is referenced form other website.
function AddContentType()
{
var ctx = new SP.ClientContext.get_current();
var filename="companybranch";
var field = ctx.get_site().get_rootWeb().get_fields().getByInternalNameOrTitle("Company_x0020_Branches");
var ctype = ctx.get_site().get_rootWeb().get_contentTypes().getById("0x01005B20AF5B57EE9045BBF0C148A600E681");
ctx.load(ctype);
ctx.load(field);
var createInfo = new SP.FieldLinkCreationInformation();
createInfo.set_field(field);
var fieldLink = ctype.get_fieldLinks().add(createInfo);
ctype.update (true);
ctx.load(fieldLink);
ctx.executeQueryAsync(success, failure);
}
function success()
{
alert('success');
}
function failure()
{
alert('failure');
}
Over all code is woking good.
But this line.
var field = ctx.get_site().get_rootWeb().get_fields().getByInternalNameOrTitle("Company");
-- column name was only adding to content type which was already presented in share point site.if we are passing anonymous name it shows failure.
Please let me know how to set the column and fields to add to content type in share point site using java script.
Reply
Answers (
0
)
Display names of files attached on a page
Update SharePoint group description using Rest API