Filter Enterprise Custom Fields with Javascript or Rest RRS feed

  • Question

  • Hi

    I am new to Sharepoint and Project Online and am trying to develop an webpart with Javascript or REST but have encountered a problem with the Enterprise Custom Fields.

    I want to filter out the non-project level enterprise custom fields (i.e. the webpart should not show Task or Resource Custom Fields). I have been searching online for quite some time, but haven't managed to find a solution.

    The closest thing I have found was the code below, but it is for SET and not GET. I have tried to use an If to filter all custom fields, but that does not work. I believe that I am using the wrong method field.get_entityTypes() but cannot find any documentation for anything else.

    MY OWN CODe, Init is called from document.ready

    function Init() { var projContext = PS.ProjectContext.get_current(); fields = projContext.get_customFields(); entityTypes = projContext.get_entityTypes(); projEntity = entityTypes.get_projectEntity(); projContext.load(fields); projContext.load(entityTypes); projContext.load(projEntity); projContext.executeQueryAsync(GetProjEntity, QueryFail); } function GetFields(sender, args) { var listItemInfo = ""; listItemInfo += "<table class='table'>"; listItemInfo += "<tr><th>Title</th></tr>"; var fieldEnumerator = fields.getEnumerator(); while (fieldEnumerator.moveNext()) { field = fieldEnumerator.get_current(); if (field.get_entityTypes() == entityTypes.projEntity) { $(field).each(function () { listItemInfo += "<tr><td>" + field.get_name() + "</td></tr>"; }); } } listItemInfo += "</table>"; $("#message").html(listItemInfo); }


    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); }

    Friday, February 26, 2016 2:35 PM