If someone could format this for me (and then remove this sentence), I would appreciate it. It's not recognizing my code snippets properly...
Alright, so instead of complicating things with Visual Studio or anything like that, I just went into the XML file for the library itself and found the "ContentType" field name.
Since my whole process is initiated from a custom drop down field on a separate page, I can pass the content type choice from that page into the custom edit form. In this case, I'm not actually using a form; I am using a normal page and
simply using SPServices "UpdateListItems." Using sessionStorage, I pass the content type from the initial page to the custom form-like page, and I just make sure to set the appropriate ContentType field to that content type passed when I hit submit.
Here we go from start to finish:
The initial page has a list dropdown formatted nicely to appear as a navigation drop-down may look. The SPServices call then builds the choices based on the content types available:
$(document).ready(function() {
$().SPServices({
operation: "GetListContentTypes",
listName: "MyLibrary",
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find("ContentType").each(function() {
contentTypeName = $(this).attr("Name");
contentTypeID = $(this).attr("ID");
var name = contentTypeName.substr(contentTypeName.indexOf(" ") + 1);
var type = name.substr(name.lastIndexOf(" ") +1);
if(name != "Folder" && name != "Document"){
$('#uploadList').append(
'<li><a href="#" onclick="uploadItem(''+contentTypeID +'')">' + name + '</a></li>'
);
}
});
}
});
});
function uploadItem(type){
sessionStorage.setItem('Type', type);
window.location = '/sitename/sitePages/CustomUpload.aspx';
}
Once the user clicks on a choice, they are redirected to the new page that is pretending to be a form. Since I stripped off parts of the name in the previous example, I am redoing the call on the new page. I should probably go back to the initial code and simplify it so I don't have to redo it on the new page, but for now, this works.
$(document).ready(function(){
type = sessionStorage.getItem('Type');
name = getContentType(type);
});
function getContentType(type){
caml = ""+type+"";
var contentTypeName = '';
$().SPServices({
operation: "GetListContentTypes",
listName: "MyLibrary",
async: false,
completefunc: function (xData, Status) {
$(xData.responseXML).find("ContentType").each(function() {
if($(this).attr("ID") == type){
contentTypeName = $(this).attr("Name");
}
});
}
});
return contentTypeName;
}
The page is designed to upload the file and submit the document properties all at the click of a single button. It starts with the document upload portion:
A submit button triggers uploadLink()-
function uploadLink(){
var queryStringVals = $().SPServices.SPGetQueryString();
var uploadID = queryStringVals["ID"];
saveFileMetadata(uploadID);
}
function saveFileMetadata(id){
//pull the data from the custom form
var title = $('#title').val();
var author = $('#author').val();
var fp = document.getElementById("FP").checked; //returns true or false
var recommended = document.getElementById("recommended").checked; //returns true or false
var org = $('#org').val();
var cocom = $('#cocom').val();
var opRel = $('#operationalRelevancy').val();
var region = $('#region').val();
var country = $('#country').val();
var threat = $('#threatActor').val();
var image = $('#imageCat').val();
var pubCat = $('#pubCat').val();
var pubTopic = $('#pubTopic').val();
var AoS = $('#areaOfStudy').val();
var analyticsCat = $('#analyticsCat').val();
var linkType = $('#linkType').val();
//establish the valuePairs for the UpdateListItems SPServices call
var valuePairs = [
["ContentType", type],
["Title", title],
["Foreign_x0020_Perspective", fp],
["Recommended", recommended],
["Organization", org],
["COCOM", cocom],
["Operational_x0020_Relevancy", opRel],
["Region", region],
["Country", country],
["Threat_x0020_Actor", threat]
];
//depending on the content type, push additional values to the valuePairs array
if(type == 'Image File'){
valuePairs.push(["Image_x0020_Category", image]);
}
else if(type == 'Publication File'){
valuePairs.push(["Publication_x0020_Category", pubCat]);
valuePairs.push(["Publication_x0020_Topic", pubTopic]);
valuePairs.push(["Product_x0020_Author", author]);
}
else if(type == 'Analytics File'){
valuePairs.push(["Analytics_x0020_Category", analyticsCat]);
valuePairs.push(["Area_x0020_of_x0020_Study", AoS]);
valuePairs.push(["Product_x0020_Author", author]);
}
else if(type == 'Link'){
valuePairs.push(["Link_x0020_Type", linkType]);
}
//run the UpdateListItems
$().SPServices({
operation: "UpdateListItems",
listName: 'MyLibrary',
ID: id,
valuepairs: valuePairs,
completefunc: function (xData, Status) {
}
});
//slight pause before redirecting to the original page
setTimeout(function() {
window.location = 'https://mysite/sitename/SitePages/StartPage.aspx';
},
500);
$("#loadingImg").hide();
}
Now using a completely custom solution, I have allowed users to select the content they are uploading and allowed them to use a customized page that functions as a form.