Loading collection options dynamically

Hey,

I’m trying to add a custom field (TheHive feature, more information here) support to the TheHive node, but I’m having a bit of trouble generating a good UI. Is it possible to load options for a collection node property (its options being INodeProperties)? I tried a bunch of stuff but the interface for INodeType seems to limit the return values of methods.loadOptions to INodePropertyOptions[] only.

Another way to create the custom fields UI would be using fixedCollection, but as the value of the custom field can be string, number, boolean, or a date, I can’t think of a way to let the user choose the value type.

Here’s what I tried with the fixedCollection:

{
    displayName: 'Custom Fields',
    name: 'customFields',
    type: 'fixedCollection',
    default: {},
    typeOptions: {
        multipleValues: true,
    },
    placeholder: 'Add Custom Field',
    displayOptions: {
        show: {
            resource: ['alert'],
        },
    },
    options: [
        {
            name: 'customFieldsUi',
            displayName: 'Custom Field',
            values: [
                {
                    displayName: 'Field',
                    name: 'field',
                    type: 'options',
                    typeOptions: {
                        loadOptionsMethod: 'loadCustomFields',
                    },
                    default: '',
                },
                {
                    displayName: 'Value',
                    name: 'value',
                    type: 'string',
                    default: '',
                    description: '',
                },
            ],
        },
    ],
},
1 Like

Is it possible to load options for a collection node property?

Found the answer to the first question, apparently not: How to create node properties dynamically?

Anyways, is there a way to get around this limitation with the fixedCollection, or am I limited to just one value type?

You can assume the datatype is always string by default and if the user wants to provide another data type can use it with expresions.

1 Like

Yeah, I guess that would work. Thanks!

I need to pass the custom fields to the API like this:

{
  "customFields": {
    "fieldName": {
      "type": "value"
    }
  }
}

I already over-engineered a solution that calls the TheHive API and gets the expected types of the custom fields, and builds the API query based on that, but should I just trust that the user gives the field value in the correct format/type so I can just determine the value type with js (typeof)? The API method would also let me do some conversions or type checks before sending the actual API request.

Yes, probably checking the API to get the type field type is too much. I wonder you can use typeof as long as the type in the api matches the types of typeof. This is a bit tricky since you have to provide the type of the field. Never seen it before. Perhaps, you can have a JSON switch and when set to true a field called Custom Fields (JSON) shows up and the user can input the fields there as JSON. When set to false, the fixedCollection shows us and the user can just provide field type string.

If you send a PR I can have a better look.

1 Like