【问题标题】:How to create an Enterprise custom field programmatically for Project Server如何以编程方式为 Project Server 创建企业自定义字段
【发布时间】:2014-11-17 09:54:49
【问题描述】:

我希望 Sharepoint 2013 应用在首次运行时以编程方式创建企业自定义字段。

我摆弄了以下代码 sn-p,但它不起作用

var projContext = PS.ProjectContext.get_current();
function AddCustomField() {
    $('#message').text('Adding Custom Field...');
    var object_to_add = new PS.CustomFieldCreationInformation();
    object_to_add.FieldType = CustomFieldType.Text;
    object_to_add.Name = "New_one";
    object_to_add.Description = "test description";
    projContext.CustomFieldCollection.add(object_to_add);
}

任何帮助将不胜感激!

【问题讨论】:

    标签: javascript sharepoint custom-fields sharepoint-apps ms-project-server-2013


    【解决方案1】:
    var projContext = PS.ProjectContext.get_current();
    var fieldType = PS.CustomFieldType.TEXT;
    var customfields = projContext.get_customFields();
    var entityTypes = projContext.get_entityTypes();
    var projEntity = entityTypes.get_projectEntity();
    var resourceEntity = entityTypes.get_resourceEntity();
    var taskEntity = entityTypes.get_taskEntity();
    
    projContext.load(customfields);
    projContext.load(entityTypes);
    projContext.load(projEntity);
    projContext.load(resourceEntity);
    projContext.load(taskEntity);
    
    projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
    
    CreateField("Test", "Test", fieldType, projEntity);
    
    function CreateField(name, description, fieldtype, entitytype) {
        var customfieldInfo = new PS.CustomFieldCreationInformation();
        customfieldInfo.set_description(description);
        customfieldInfo.set_name(name);
        customfieldInfo.set_fieldType(fieldtype);
        customfieldInfo.set_entityType(entitytype);
    
        customfields.add(customfieldInfo);
        customfields.update();
        projContext.load(customfields);
        projContext.executeQueryAsync(QuerySucceeded, QueryFailed);
    
    }
    

    【讨论】:

    • 请为您的答案添加一些解释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    相关资源
    最近更新 更多