Get values from array.object using business rule

Nihal Sarawgi1
Tera Contributor

Below is the response I get from an action in flow designer

This is of the type array.Object

{
    "Translations": [
        {
            "detected_language": "en",
            "text_translations": [
                {
                    "target_language": "es",
                    "translated_text": "Hola Mundo"
                }
            ]
        }
    ]
}

From this i want to fetch "translate_text" only in business rule. Please let me know how can i achieve this .

2 ACCEPTED SOLUTIONS

Valmik Patil1
Kilo Sage

Hello @Nihal Sarawgi1 ,

 

You need to run your action in BR in order to get result. And then

Refer below script to fetch value of key.

var obj = {
    "Translations": [{
        "detected_language": "en",
        "text_translations": [{
            "target_language": "es",
            "translated_text": "Hola Mundo"
        }]
    }]
};

gs.info(obj.Translations[0].text_translations[0].translated_text);

thanks,

Valmik Patil

View solution in original post

Juhi Poddar
Kilo Patron

Hello @Nihal Sarawgi1 

Please try this:

 

// Assuming the data is already an Array.Object
var response = {
    "Translations": [
        {
            "detected_language": "en",
            "text_translations": [
                {
                    "target_language": "es",
                    "translated_text": "Hola Mundo"
                }
            ]
        }
    ]
};

// Navigate to the 'translated_text'
var translatedText = response.Translations[0].text_translations[0].translated_text;

// Log or use the extracted value
gs.info('Translated Text: ' + translatedText);

 

Result:

JuhiPoddar_0-1732688583780.png

Hope this helps!

 

"If you found my answer helpful, please give like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

View solution in original post

3 REPLIES 3

Valmik Patil1
Kilo Sage

Hello @Nihal Sarawgi1 ,

 

You need to run your action in BR in order to get result. And then

Refer below script to fetch value of key.

var obj = {
    "Translations": [{
        "detected_language": "en",
        "text_translations": [{
            "target_language": "es",
            "translated_text": "Hola Mundo"
        }]
    }]
};

gs.info(obj.Translations[0].text_translations[0].translated_text);

thanks,

Valmik Patil

Juhi Poddar
Kilo Patron

Hello @Nihal Sarawgi1 

Please try this:

 

// Assuming the data is already an Array.Object
var response = {
    "Translations": [
        {
            "detected_language": "en",
            "text_translations": [
                {
                    "target_language": "es",
                    "translated_text": "Hola Mundo"
                }
            ]
        }
    ]
};

// Navigate to the 'translated_text'
var translatedText = response.Translations[0].text_translations[0].translated_text;

// Log or use the extracted value
gs.info('Translated Text: ' + translatedText);

 

Result:

JuhiPoddar_0-1732688583780.png

Hope this helps!

 

"If you found my answer helpful, please give like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

FredricS
Tera Contributor

I'm a noob in this field but I find it impossible to get the right information from the Array.Object. Doing translated text and want to update short description in an incident. 

 

Like this:

FredricS_0-1742910397958.png

 

 

Am I doing it completely wrong here?