# Inject js makes string instead array

**URL:** <https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349>\
**Category:** Activities\
**Tags:** question, uiautomation, webapi, activities\
**Created:** [July 13, 2021, 1:15pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349 "2021-07-13T13:15:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akobir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akobir/32/178511_2.png) [@Akobir](https://forum.uipath.com/u/Akobir)\
**Post date:** [July 13, 2021, 1:15pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/1 "2021-07-13T13:15:32Z")

</div>

Hi everyone!  
I tried to search, but didn’t find the answer.

I added “Inject js” to my activitie and my js code makes array as output, but Ui changes it to string.  
How I can get array?  
Thank you in advance!

---

<div class="post-metadata">

**Author:** ![Nithinkrishna](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/nithinkrishna/32/561519_2.png) [@Nithinkrishna](https://forum.uipath.com/u/Nithinkrishna)\
**Post date:** [July 13, 2021, 1:31pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/2 "2021-07-13T13:31:32Z")

</div>

Sorry could you please explain that conversion part what is happening.

If possible with screenshots.

Thanks  
#nK

---

<div class="post-metadata">

**Author:** ![gustavo.cervelin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gustavo.cervelin/32/520628_2.png) [@gustavo.cervelin](https://forum.uipath.com/u/gustavo.cervelin)\
**Post date:** [July 13, 2021, 1:39pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/3 "2021-07-13T13:39:10Z")

</div>

Hi @Akobir,

According to Inject JS Script activity documentation, it is only possible to return String.

> **[Inject JS Script](https://docs.uipath.com/activities/docs/inject-js-script)**
>
> UiPath.Core.Activities.InjectJsScript Executes JavaScript code in the context of the web page corresponding to a UiElement. Properties Input ScriptCode - The JavaScript code you want to run. You can write it here as a string, or add the full path of...

But, you can try a workaround…

Instead of returning your array, try this:

`return JSON.stringfy(yourArrayVariable)`

Then, you just need to Deserialize it:

> **[Deserialize Json Array](https://docs.uipath.com/activities/docs/deserialize-json-array)**
>
> UiPath.WebAPI.Activities.DeserializeJsonArray Deserializes a JSON array string to a JArray object. Properties Common DisplayName - The display name of the activity. Input JsonString - The string containing the JSON array to be deserialized. The JSON...

> **[Deserialize Json](https://docs.uipath.com/activities/docs/deserialize-json)**
>
> UiPath.WebAPI.Activities.DeserializeJson Deserializes the JSON string to a JObject. Properties Common DisplayName - The display name of the activity. Input JsonString - The string containing the JSON to be deserialized. The JSON should be written...

If you need more details, let me know.

Kindly mark this answer as solution if it helped you.

---

<div class="post-metadata">

**Author:** ![Akobir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akobir/32/178511_2.png) [@Akobir](https://forum.uipath.com/u/Akobir)\
**Post date:** [July 13, 2021, 1:57pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/4 "2021-07-13T13:57:48Z")

</div>

Hi, Gustavo! Thank you for your answer, it was very helpful!  
Maybe you have any example of workaround?

---

<div class="post-metadata">

**Author:** ![Akobir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akobir/32/178511_2.png) [@Akobir](https://forum.uipath.com/u/Akobir)\
**Post date:** [July 13, 2021, 1:58pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/5 "2021-07-13T13:58:36Z")

</div>

Thank you for your answer! I’ll try to use Gustavo’s workaround.

---

<div class="post-metadata">

**Author:** ![gustavo.cervelin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gustavo.cervelin/32/520628_2.png) [@gustavo.cervelin](https://forum.uipath.com/u/gustavo.cervelin)\
**Post date:** [July 13, 2021, 2:10pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/6 "2021-07-13T14:10:05Z")

</div>

Hi @Akobir,

I’ll build an example here and share with you as soon as possible.

Thanks

---

<div class="post-metadata">

**Author:** ![Akobir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akobir/32/178511_2.png) [@Akobir](https://forum.uipath.com/u/Akobir)\
**Post date:** [July 13, 2021, 2:11pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/7 "2021-07-13T14:11:33Z")

</div>

Gustavo, thanks!  
I found the example in uipath docs, but I can’t find deserialize activitie.  
If it possible - can you help me with this, pls?

---

<div class="post-metadata">

**Author:** ![gustavo.cervelin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gustavo.cervelin/32/520628_2.png) [@gustavo.cervelin](https://forum.uipath.com/u/gustavo.cervelin)\
**Post date:** [July 13, 2021, 2:18pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/8 "2021-07-13T14:18:51Z")

</div>

Hi @Akobir,

Sure, I’ll help you… just give me some time to finish the example I am creating here.

---

<div class="post-metadata">

**Author:** ![gustavo.cervelin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gustavo.cervelin/32/520628_2.png) [@gustavo.cervelin](https://forum.uipath.com/u/gustavo.cervelin)\
**Post date:** [July 13, 2021, 3:06pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/9 "2021-07-13T15:06:58Z")

</div>

@Akobir, check it out:

[InjectJsScriptReturningArray.zip](https://forum.uipath.com/uploads/short-url/kOk1Q7qwJEa0DLLE6I9QYgXlY9h.zip) (3.1 KB)

Note: You must install UiPath.WebAPI.Activities dependence

---

<div class="post-metadata">

**Author:** ![Akobir](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/akobir/32/178511_2.png) [@Akobir](https://forum.uipath.com/u/Akobir)\
**Post date:** [July 14, 2021, 8:43am UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/10 "2021-07-14T08:43:41Z")

</div>

Thank you very much!  
And else one question - how I can get a value from deserialize array?  
For example, I have array with 2 columns  
[  
“result1,  
result2”  
]  
Can I get “result2” to messagebox?

---

<div class="post-metadata">

**Author:** ![gustavo.cervelin](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/gustavo.cervelin/32/520628_2.png) [@gustavo.cervelin](https://forum.uipath.com/u/gustavo.cervelin)\
**Post date:** [July 14, 2021, 1:22pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/11 "2021-07-14T13:22:39Z")

</div>

Hello @Akobir,

You’re welcome 🙂

Yes, it is totally possible.

You can use Split, considering that you have an array of String where each item is separeted by comma.

Check the updated solution if necessary

[InjectJsScriptReturningArray.zip](https://forum.uipath.com/uploads/short-url/rTjYt38ie9Tufxi8DbJBRbyI4ai.zip) (3.3 KB)

If you need extra help, let me know

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [July 17, 2021, 1:23pm UTC](https://forum.uipath.com/t/inject-js-makes-string-instead-array/329349/12 "2021-07-17T13:23:20Z")

</div>

Closed on July 17, 2021, 1:23pm UTC

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