Unable to set value for nested fields using interface methods

I wanted to dynamically set values for a nested field in ticket creation page and when i run the following code:

                client.interface
                  .trigger("setValue", {
                    id: fieldName,
                    value: value,
                  })
                  .then(
                    function (data) {
                      debug(data, "doAction");
                    },
                    function (error) {
                      debug(error, "doAction");
                    }
                  );

I get the following console.log without any changes to thefield i am targetting on ticket creation page.

{
    "message": "Ok"
}

image

Screenshot of the targeted nested field after the function execution.

I tried representing values in multiple ways like:

val = `{${val} : {}}`
value: [val]

//and

value: [JSON.Parse(val)]

//and without []

And i keep getting the same {message: Ok} on the console without any changes to the UI

The following is the object with the properties of nested field i am trying to target

{
    "id": 29000224796,
    "label": "product type",
    "description": "",
    "field_type": "nested_field",
    "created_at": "2023-12-26T05:15:41Z",
    "updated_at": "2023-12-26T05:15:41Z",
    "position": 23,
    "required_for_closure": false,
    "name": "product_type",
    "default_field": false,
    "required_for_agents": false,
    "customers_can_edit": true,
    "label_for_customers": "product type",
    "required_for_customers": false,
    "displayed_to_customers": true,
    "belongs_to_section": false,
    "choices": [
        {
            "id": 29000157113,
            "display_id": 47,
            "value": "Mobile",
            "nested_options": [
                {
                    "id": 29000157114,
                    "display_id": 48,
                    "value": "Phones",
                    "nested_options": [
                        {
                            "id": 29000157115,
                            "display_id": 49,
                            "value": "item 1"
                        },
                        {
                            "id": 29000157116,
                            "display_id": 50,
                            "value": "item 2"
                        }
                    ]
                },
                {
                    "id": 29000157117,
                    "display_id": 51,
                    "value": "Tablets",
                    "nested_options": [
                        {
                            "id": 29000157118,
                            "display_id": 52,
                            "value": "item 1"
                        },
                        {
                            "id": 29000157119,
                            "display_id": 53,
                            "value": "item 2"
                        }
                    ]
                },
                {
                    "id": 29000157120,
                    "display_id": 54,
                    "value": "Smart Watches",
                    "nested_options": []
                }
            ]
        },
        {
            "id": 29000157121,
            "display_id": 55,
            "value": "Laptops",
            "nested_options": [
                {
                    "id": 29000157122,
                    "display_id": 56,
                    "value": "Gaming",
                    "nested_options": [
                        {
                            "id": 29000157123,
                            "display_id": 57,
                            "value": "item 1"
                        },
                        {
                            "id": 29000157124,
                            "display_id": 58,
                            "value": "item 2"
                        }
                    ]
                }
            ]
        }
    ],
    "nested_fields": [
        {
            "name": "product_category",
            "id": 29000021980,
            "label": "product category",
            "label_in_portal": "product category",
            "level": 2,
            "description": "",
            "created_at": "2023-12-26T05:15:41Z",
            "updated_at": "2023-12-26T05:15:41Z",
            "field_id": 29000224796
        },
        {
            "name": "product",
            "id": 29000021981,
            "label": "product",
            "label_in_portal": "product",
            "level": 3,
            "description": "",
            "created_at": "2023-12-26T05:15:41Z",
            "updated_at": "2023-12-26T05:15:41Z",
            "field_id": 29000224796
        }
    ],
    "sections": [],
    "workspace_id": 2
}

Any help would be appreciated

Hey @falconZ,

While working with interface methods, it can set values to individual fields - Freshworks Developer Docs | Use interface methods but if you are looking at setting multiple fields/nested fields you would have to do it sequentially as the async response of .then() would return a success status of setValue.

I ran into the issue as i was using the id of the choice instead of its name. Replacing id with name seems to have fixed the issue for me.

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.