1

I create a list using:

function createProjectList() {
    var clientContext = new SP.ClientContext.get_current();
    var oWebsite = clientContext.get_web();
    var listCreationInfo = new SP.ListCreationInformation();
    listCreationInfo.set_title('Projects');
    listCreationInfo.set_templateType(100);
    this.oList = oWebsite.get_lists().add(listCreationInfo);
    clientContext.load(oList);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onCreatedProjectList), Function.createDelegate(this, this.onQueryFailed));
}

and then I use this to define the list

function onCreatedProjectList() {
var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('Project');

    //what is the setter/property for define the following field as date only instead of date and time. DateTime is just the internal type, so ?
    this.fieldValue = oList.get_fields().addFieldAsXml('<Field DisplayName=\'ProjectDueDate\' Type=\DateTime\' />', true, SP.AddFieldOptions.defaultValue);
    var fieldVal = clientContext.castTo(fieldValue ,SP.FieldNumber);
    fieldVal.update();
    clientContext.load(fieldValue );

    fieldCollection = oList.get_fields();
    this.oneField = fieldCollection.getByInternalNameOrTitle("Title");
    this.oneField.set_hidden(true);
    this.oneField.set_defaultValue('...');
    this.oneField.set_required(false);
    this.oneField.update();
    clientContext.load(this.fieldCollection);
    clientContext.load(this.oneField);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onCompletedProjectList), Function.createDelegate(this, this.onQueryFailed));
}
4

Try adding:

Format=\'DateOnly\' 

to xml field definition.

So, that line in your code would be:

this.fieldValue = oList.get_fields().addFieldAsXml('<Field DisplayName=\'ProjectDueDate\' Type=\DateTime\' Format=\'DateOnly\' />', true, SP.AddFieldOptions.defaultValue);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.