Custom fields specific to a project, not workspace

I’m trying to create projects via the API and each project has to have some custom fields.

From what I read in the docs, the way to do this is to

  1. create custom fields in the workspace and then
  2. assign the custom fields using custom_fields_settings to the project.

Is there a way to create custom fields which are not in the workspace, but rather exist only for a single project?

The reason behind me wanting to do this is that custom fields with the same name will be used in more than one project, but their enum values need to be different.

I believe there is a way to do this, perhaps undocumented, because if I create a project using CSV import in the GUI, the custom fields are not visible in the workspace, but are present in the project when accessed via the API.

Hi @Goran_Radola and welcome to the forum,

I think you’re right that there’s not a way to create a local project-specific custom field via the API.

I haven’t used it but there is an is_global_to_workspace property on a custom field; you might want to play around with setting that and see if that helps you.

Hi! Thanks for the reply!

It gave me something to search the forum with and I’ve found the solution in these two topics:

The gist is, you need to send a POST to addCustomFieldSetting just like in the docs, but instead of setting custom_field to an existing GID, you pass a JSON definition of a custom field.

In my case, when using the Node API, it looks something like this:

client.projects.addCustomFieldSettingForProject(
  project.gid, { 
    custom_field: { 
      name: 'Test Custom Field', 
      type: 'enum', 
      enum_options: [{ name: 'first' }, { name: 'second' }], 
      "resource_subtype": "enum"
    },
  is_important: true 
});

Afterwards, the added custom field is visible in the project’s custom_field_settings.

Ah, excellent, thanks, @Goran_Radola!