Inject JS with multiple parameter

Hello ,
I’m trying to use java script with multiple parameter as input but uipath takes only string any suggestion ?

Sample script is as below:

I have to pass this 3 variable’s value inSSNp3,inLstname,inFstname ?

function(element,inSSNp3,inLstname,inFstname) {
document.getElementById(id=“cphMain_cphMain_chbSCssn”).click()
var ssnp3 = document.getElementById(id=“cphMain_cphMain_txtSCSsn_txtSCSsn_part3”)
ssnp3.value =inSSNp3
var lstname = document.getElementById(id=“cphMain_cphMain_txtSCLstNa”)
lstname.value =inLstname
var fstname = document.getElementById(id=“cphMain_cphMain_txtSCFstNa”)
fstname.value =inFstname
}

Hi @apurvalost ,

Using JSON.parse and JSON.stringify should help you in this case. See the example in the photos.

Vlad

input_example

2 Likes

Hi @vlad.coteanu thanks for that help appreciated but would you mind explaining how to use same in my above sample script with this json.parse ?

Your function should be like this, Make sure you escape the double quotes when assigning this to a variable in Studio. If your default language is VisualBasic, then this is done by adding another double-quote. For example: myString = "function(e,a) {document.getElementById("id"); }" will probably throw an error. Alternatively, you should write it like this: myString = "function(e,a) {document.getElementById(""id""); }"

function(element,inDataStr) {
    var dataJson = JSON.parse(inDataStr);
    document.getElementById(id=“cphMain_cphMain_chbSCssn”).click()
    var ssnp3 = document.getElementById(id=“cphMain_cphMain_txtSCSsn_txtSCSsn_part3”)
    ssnp3.value = dataJson.inSSNp3
    var lstname = document.getElementById(id=“cphMain_cphMain_txtSCLstNa”)
    lstname.value =dataJson.inLstname
    var fstname = document.getElementById(id=“cphMain_cphMain_txtSCFstNa”)
    fstname.value =dataJson.inFstname
}

The input data should be assigned like this (escaping the double quotes in VB style):
“{”“inSSNp3"”:““value1"”, ““inLstname””:”“value2"”, ““inFstname””:““value3"”}”

1 Like

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