Inject js Return value is array

Hello Everyone,
When i use inject js activity and that js file return array that time i store that data into array type generic and that give me error. so my question is which type of variable i use to store javascript array in uipath.

Thanks
Urvin :slight_smile:

Did you assign the variable type by yourself or was it auto-assigned using Ctrl+K?

i assign…

@monsieurrahul i also try to assign using Ctrl+K but that’s not work.

@monsieurrahul
Give a try to set wip_data to Datatype Object and inspect the returned result in Debugger. Maybe you can post a screenshot from this.

Would be serialisation of the array at JS side and returning the serialized string an option four you?

1 Like

@ppr
if i do that then how to iterate that data in uipath manes data store in object variable then how to iterate object variable.

Thanks

@Urvin_Sanghavi
I didn’t get your question. Could you please help with a screenshot?

@ppr
Yaa sure.

Please debug your process, do breakpoint after inject js activity and take screenshot from the returned result of inject js. Does mean: show from locals pane what is returned.

1 Like

@Urvin_Sanghavi
Lets assume: FundCode is the returned string from inject JS Activity.

Now Give a try to this string and do a deserialisation with the help of Newtonsoft (provided e.g. Webactivities Package) into an String array

This result you can use in the for each. Ensure the typeArgument(For each activity) is set to String

You might consider:

  1. Modify your javascript to concatenate your array values with a character (i.e. | )
  2. Call your Javascript in Uipath and take an input with data type of string.
  3. Then call an assign activity, Set arrList = out_string.Split("|"c)
1 Like

@ppr
Fundcode return serialize from the inject js.
so first i have to deserialize?if yes then how?

js file return JSON.stringify(funds);
funds datatype is array in js file

@Urvin_Sanghavi
Assign Activity: Newtonsoft.Json.JsonConvert.DeserializeObject(Of String())(FundCode)
should return a String Array
Ensure Newtonsoft is imported into namespaces
Hint from @Emman_Pelayo would also be an option

@ppr
i import Newtonsoft.Json after that showing me this.

hey @Emman_Pelayo,
this is a right way to get the data from the inject JS.
if i have 1000 of recorders then this option give me string with concatenation right but other way i store that data into array in js file and that js array return that’s goodway to get data or not?

1 Like

@Urvin_Sanghavi
ensure UiPath Web Activities is referenced
ensure Newtonsoft namespace is correctly imported.

If any errors stll occur. close/open xaml, close/open UiPath project.

1 Like

Thank You @ppr
This work for me.

1 Like

Great I am also happy about this :+1:

1 Like

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