Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
0
Reply
How to site column to content type using js
Gowtham
Mar 2 2017 9:23 AM
267
Reply
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.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
Display names of files attached on a page
Update SharePoint group description using Rest API