new CustomField()

This class provides support for custom fields.

List a webapp's custom fields

var fieldsCollection = new BCAPI.Models.WebApp.CustomFieldCollection("WEBAPP-NAME"),
response = fieldsCollection.fetch();

response.done(function () {
    fieldsCollection.each(function (field) {
        console.log(JSON.stringify(field))
    });
}).fail(function (jqXHR) {
    console.log("Could not list the custom fields.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
});

Create a new custom field

var customField = new BCAPI.Models.WebApp.CustomField("test app2", {
    "id": 3,
    "name": "Part code",
    "type": "String",
    "required": false
}, true);

customField.save({
    success: function(fieldModel) {
        // do something on success.
    },
    error: function (jqXHR) {
    console.log("Request failed.");
    console.log("Error code: " + jqXHR.status);
    console.log("Error text: " + jqXHR.statusText);
    console.log("Response text: " + jqXHR.responseText);
}
});

In the attributes, the id must be passed.

The last parameter specifies if the custom field is new or exists already. This is used to determine the correct HTTP verb to call since the id is always passed. If omitted, it is assumed that the custom field is new.

Source:


Error Codes

This method will return the following error codes:

  • 201 - created
  • 400 - bad request; sub-error codes:
    • 210000 - An unspecified error has occurred
    • 210002 - Invalid field id specified
    • 210003 - Invalid name (name is not syntactically correct or there is already a system or custom field with the same name)
    • 210004 - Invalid listItems
    • 210005 - Invalid dataSourceName
    • 210006 - Invalid order value (must be between 1 and max existing order value + 1)
    • 210007 - Invalid type
  • 401 - unauthorized - when the authentication token is incorrect
    • 101000 - sub-error code
  • 403 - forbidden - when the user does not have Edit WebApp Permission
  • 404 - not found
    • 190001 - The web app could not be found (the webAppName param from the URL does not match)
    • 210001 - The custom field was not found (the fieldId from the URL do not match)