How to pass multiple input parameter in inject js activity in uipath

Hi

How to pass multiple input parameter in inject js activity in UiPath

@Sankaraveni_Murugan

Welcome to the community

You can append the string using comma or any other separator and then split in your code…Please check the below

cheers

Can you provide the screenshots of the properties panel of Inject js activity. so that I can see the syntax of how to pass 2 input parameters in inject js activity

@Sankaraveni_Murugan

you would pass like this…

if you open the link provided also you will see same…basically say you need to pass 3 text inputs…you will concatenate them with any character and send as one string and then split in your javascript to get each value separately

Here value is the only variable which can take inputs…so if you need to pass all 3…pass as how in picture and then as shown in sample code split it with comma and use it

image

Variables

Samplecode:
function(e, value){
var optionsToSelect = value.split(“,”);
for ( var i = 0, l = e.options.length, o; i < l; i++ )
{
o = e.options[i];
o.selected = false;
test = o.text;
for( var j = 0; j < optionsToSelect.length; j++){
if(optionsToSelect[j] == o.text){
o.selected = true;
break;
}
}
}
}

Hope this helps

Cheers

HI,

How about using JSON? We can easily parse it in JavaScript.
(Please install UiPath.WebAPI.Activities package in advance)

id ="2"
name ="John Smith"
strJson = NewtonSoft.Json.JsonConvert.SerializeObject(New Dictionary(Of String,String)From{{"ID",id},{"Name",name}})

Then set strJson at InputParameter property in InjectJSscript actiivty

JavaScript Code is as the following, for example.

function(e,v) {
    const obj = JSON.parse(v);
    e.value=(obj.ID + obj.Name);
}

Sample20230327-2L.zip (2.9 KB)

Regards,