Freshdesk custom fields name issue

Hey guys,
I’m facing really weird problem. I don’t know what happened behind the scenes but for our company we have freshdesk field (in the production) where we use orderNr as a custom field. But interesting fact is I’ve opened my own account to avoid any serious problem in the live system of our working freshdesk production, and made a dummy environment to create and test my apps before installing it in the production. Let’s say it’s a developer environment. However, the custom field orderNr have different way of calling in the freshdesk itself. For the production it called

order_no

where for me it’s called

cf_ordernr

. However, When we were creating the field the names were same. So to avoid this issue I have said okay let’s parameterized this orderNr field since it called different from environment to environment which is really weird. Now there is another problem. When I try to fetch the orderNr this dynamic way kinda this way:

client.data.get(“ticket”)
.then(
function (data) {
var orderNr = ‘data.ticket.custom_field’+‘.’+ FIELDPARAMNAME;

                        console.log('orderNr: '+orderNr);
                       
                         initOrderTool();
                        initPodioService(client);
                    }
                );

However, it doesn’t work as it should work. I want to use this as an expression not as a string or an object. However, this is where I’m facing some challenges for example, orderNr is 1234567 it shows me

data.ticket.custom_field.cf_ordernr

not the 1234567. Besides, I know it works with

eval()

but it’s not a professional way to use and isn’t secured too. However, when I try to pass this using

var tempODN = new Function(‘a’,“return a”);

now freshdesk gives me error like this:

VM129:3 Uncaught (in promise) ReferenceError: data is not defined at eval (eval at (VM124 app.js:1562), :3:1)

. I don’t understand why? Is there any better option to do so? Thanks everyone. :slight_smile:

Hi @Shamsuzzaman_Sadi,

Thanks for your detailed explanation of the issue with the proper code snippet and error.

The custom fields are returned in a different format now and it differs from the documentation it seems. I will verify this and propose the changes to the documentation to reflect the proper way.
I will check with the Freshdesk product team and will update here on why the custom field format looks different in a different environment.

To make your workaround of dynamically fetch the custom field value, the following way can be followed to fetch the value of the custom field dynamically. Please if there’s an issue with this still.

var orderNr = data.ticket.custom_fields[FIELDPARAMNAME];
console.log('orderNr: '+orderNr);

1 Like

Thanks Raviraj. Now it’s working. :slight_smile:

1 Like