Hello,
I couldn't find a forum here for SharePoint 2016 which is why I'm posting in the 2013 forum. I have created a document library in SharePoint 2016 and assigned a custom content type that I created deriving from DocumentSet. I added all the columns I wanted to this custom document set. The fields consist of text, lookup fields that allow multiple values, and there is also a User field.
Below is my code for the add new form where the error is occurring.
function WebForm_DoPostBackCustom(){
// GET FORM DATA & VALIDATE
///....HIDING THIS CODE FOR SIMPLICITY
// CREATE OBJECT TO SEND TO SHAREPOINT LIST
var properties = {};
properties['Title'] = name; //TEXT FIELD
properties['FileLeafRef'] = name; //? NOT SURE IF I NEED THIS
properties['Item_x0020_Code'] = itemCode; //TEXT FIELD
properties['Change_x0020_Control_x0020__x0023_'] = changeControl;//NUMBER FIELD
properties['Countries'] = countries;//TEXT FIELD
properties['Justification_x0020__x0026__x0020_Impact_x0020_of_x0020_NOT_x0020_Doing_x0020_Change'] = justification; //TEXT FIELD
properties['Market_x0020_Notification'] = marketNotification;//TEXT FIELD
properties['Distributor_x0020_Notification'] = distributorNotification;//TEXT FIELD
properties['Department_x0020_Expert'] = departmentExpert; //THIS IS A PERSON FIELD
var selectedChangeTypes = [];
for (var i = 0; i < changeTypes.length; i++)
{
var newLookupField = new SP.FieldLookupValue();
newLookupField.set_lookupId(changeTypes[i]);
selectedChangeTypes.push(newLookupField);
}
properties['Change_x0020_Types'] = selectedChangeTypes;//MULTI VALUE LOOKUP FIELD
var selectedImpacts = [];
for (var i = 0; i < impacts.length; i++)
{
var newLookupField = new SP.FieldLookupValue();
newLookupField.set_lookupId(impacts[i]);
selectedImpacts.push(newLookupField);
}
properties['Impacts'] = selectedImpacts;//MULTI VALUE LOOKUP FIELD
var selectedDepartmentApprovals = [];
for (var i = 0; i < departments.length; i++)
{
var newLookupField = new SP.FieldLookupValue();
newLookupField.set_lookupId(departments[i]);
selectedImpacts.push(newLookupField);
}
properties['Department_x0020_Approvals'] = selectedDepartmentApprovals//MULTI VALUE LOOKUP FIELD
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web(); ctx.load(web);
var list = web.get_lists().getByTitle('Change Control Requests (New)');
ctx.load(list);
var parentFolder = list.get_rootFolder();
ctx.load(parentFolder);
var docSetContentTypeID = "0x0120D520007B4459305E909F40A1D7E88011667252001AF0C6716A90D743A9D81C085D07EC62";
var docSetContentType = ctx.get_site().get_rootWeb().get_contentTypes().getById(docSetContentTypeID);
ctx.load(docSetContentType);
ctx.executeQueryAsync(function () {
SP.DocumentSet.DocumentSet.create(ctx, parentFolder, docSetName, docSetContentType.get_id());
var docSetFolder = web.getFolderByServerRelativeUrl(parentFolder.get_serverRelativeUrl() + '/' + docSetName);
var docSetFolderItem = docSetFolder.get_listItemAllFields();
if (properties != null)
{
for (var property in properties) {
if (properties.hasOwnProperty(property) === true) {
docSetFolderItem.set_item(property, properties[property]);
}
}
}
docSetFolderItem.update();
ctx.load(docSetFolderItem);
ctx.executeQueryAsync(function () {
addChangeControlSuccess(docSetFolderItem);
}, requestFailure);
},requestFailure);
}
function addChangeControlSuccess(data)
{
console.log(data);
}
function requestFailure(sender,args)
{
console.log('Request Failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
I am currently getting the error: "Object reference not set to an instance of an object on server. The object associated with method GetById."
It is throwing the error on line:
SP.DocumentSet.DocumentSet.create(ctx, parentFolder, docSetName, docSetContentType.get_id());
Any help on what I am doing wrong is greatly appreciated! Thank you so much!
~ Frankie