How to create an Enterprise custom field programmatically for Project Server RRS feed

  • Question

  • Hello!

    I want a Sharepoint 2013 app to create programmatically an Enterprise Custom Field when it runs for the first time.

    I fiddled around with the following code snippet, but it's not working

    var projContext = PS.ProjectContext.get_current();  
    function AddCustomField() {
            $('#message').text('Adding Custom Field...'); 
            var object_to_add = new PS.CustomFieldCreationInformation();
            object_to_add.set_description("test description");  

    Any help would be appreciated!

    • Edited by Lorant-DLD Monday, November 17, 2014 12:10 PM edit in code
    Monday, November 17, 2014 12:10 PM

All replies

  •  projContext.CustomFieldCollection.Update();

    Tuesday, November 18, 2014 7:32 AM
  • Thank you for replying, but this wouldn't help : 

    My code looks like this now : 

    'use strict';
    var projContext;
    var resources;
    // This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
    $(document).ready(function () {
        projContext = PS.ProjectContext.get_current();
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', AddCustomField); //when the page loads, we execute this method
    function AddCustomField() {
        $('#message').text('Adding Custom Field...');
        var object_to_add = new PS.CustomFieldCreationInformation();
        object_to_add.set_description("test description");

    Am I missing something?

    Tuesday, November 18, 2014 11:16 AM
  • I like this work on C#

    CustomFieldCreationInformation customFieldCreationInformation = new CustomFieldCreationInformation();
                customFieldCreationInformation.Id = new Guid();
                customFieldCreationInformation.Name = nameField;
                customFieldCreationInformation.LookupTable = table;
                customFieldCreationInformation.FieldType = fieldType;
                customFieldCreationInformation.EntityType = entityType;

    may need to set the values "Id", "EntityType", "FieldType"

    Wednesday, November 19, 2014 4:56 AM
  • Hi!

    Since the PS javascript SDK is incredibly bad, and poorly documented, I have to come to you guys with my questions.

    I want to programmatically create an Enterprise calendar using a Sharepoint 2013 app.

    I have the following code which is called from the main function of the javascript file : 

    function CreateCalendar() {
        var eCalColl = projContext.get_calendars(); //get calendar collection
        var ccinfo = new PS.CalendarCreationInformation();
        projContext.executeQueryAsync(Function.createDelegate(this, function () {
            // Display the results and remove the progress msg
            alert("Calendar added successfully");
        }), Function.createDelegate(this, function (call, error) {
            alert("Error : " + error.get_message());

    It executes the query, but has the following error message: 


    which, according to the error message list : Value=13038. The GUID is not valid to duplicate a calendar.

    I don't want to duplicate anything, I set every field of the CalendarCreationInformation object accordingly, and it's still not working.

    I even tried duplicating a calendar, but it's not working.

    Wednesday, November 19, 2014 8:42 AM
  • Thank you for the reply!

    I understand the C# code, but I can't really translate it to javascript, since the functions have different names, and well, intellisense is not working for JSOM.

    I have the following concerns : 

    - How can I create a new GUID in javascript programmatically?

    - After I add the nnew CustomFieldCreationInformation object to the custom field "collection", do I have to update, or run a query or what?

    The documentation on this is so incredibly poor...

    Wednesday, November 19, 2014 9:14 AM
  • try http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript

    update and run a query

    Wednesday, November 19, 2014 12:15 PM
  • Hi Lorant,

    I merged your duplicated threads.

    Hope this helps,

    Guillaume Rouyre, MBA, MVP, P-Seller |

    Wednesday, November 19, 2014 1:03 PM