Mixed type in mappable parameters

I have a field “duration” which has several options according to their API docs: “A duration can be one of the following… “NONE”, “REMINDER”, or a integer greater than 0”

So it is either text or integer. I now have a text field which I thought would support both:

  {
    "name": "duration",
    "type": "text",
    "label": "Duration",
    "help": "A duration can be one of the following... \"NONE\", \"REMINDER\", or a integer greater than 0"
  }

However if I try to use the field in my module and enter a number I get a 400 error “Bad Request”.

body: 
error: "Bad Request"
message: Array(1)
0: "duration can only be \"NONE\", \"REMINDER\" or an integer greater than 0"

Input data:

[
    {
        "name": "Test task",
        "status": "todo",
        "dueDate": "2024-02-10T03:00:00.000Z",
        "duration": **"120"**,
        "projectId": "b966fH76KAAToJaA92YBz",
        "description": "Link: https://testlink",
        "workspaceId": "weD2Y4Zf44sI6KQ0XXzHm",
        "autoScheduled": {
            "startDate": "2024-02-05T03:00:00.000Z"
        }
    }
]

When I set it to uinteger, the error is fixed because the quotes are removed in the API call. Due to the way the field is used, I don’t feel a nested select field is the best option. I want my users to be able to use general functions to determine the actual content. For example:

Screenshot 2024-02-07 at 09.25.26

So what would be the best way to configure this parameter to support this mixed type for the app users? Is there a way to change the type based on the inputted data?

You have two fields.

  {
    "name": "durationType",
    "type": "select",
    "label": "Duration Type",
    "options": [
      { "label": "MINUTES", "value": "MINUTES" },
      { "label": "NONE", "value": "NONE" },
      { "label": "REMINDER", "value": "REMINDER" }
    ],
    "default": "MINUTES"
  },
  {
    "name": "durationMins",
    "type": "uinteger",
    "label": "Duration (mins)",
    "help": "If Duration Type is \"NONE\" or \"REMINDER\", this field is ignored."
  }

See where I’m getting at?

2 Likes

Thanks, but as I said I’m trying to prevent using multiple fields. This is to improve user experience. So if anyone has a different solution, please let me know.

For now I’ve used this for parameters:

  {
    "name": "durationSelect",
    "type": "select",
    "label": "Duration",
    "help": "A duration can be one of the following... \"NONE\", \"REMINDER\". To specify a value, use the field below",
    "options": [
      {
        "label": "NONE",
        "value": "NONE"
      },
      {
        "label": "REMINDER",
        "value": "REMINDER"
      }
    ]
  },
  {
		"name": "durationMinutes",
    "type": "uinteger",
		"label": "Minutes",
    "help": "This fields overrides the Duration select field above. Leave this empty to use \"NONE\" or \"REMINDER\" options."
  }

And used a function in s the communication to calculate the data:

	"body": {
		"{{...}}": "{{omit(parameters, 'durationSelect', 'durationMinutes')}}",
		"duration": "{{ifempty(parameters.durationMinutes, parameters.durationSelect)}}"
	}

1 Like