In UI Page, how to send a variable value from client script to processing script ?

Swarnim1
Tera Expert

I need to pass a variable value which is declared in Client Script to Processing Script.

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

So in your HTML, you'd want to put a hidden input like:

<input type="hidden" id="jvar_answer" name="jvar_answer" value=""/>

Then in your client script, set this id to a value:

gel('jvar_answer').value = "42";

In your processing script, you now get to refer to it as:

jvar_answer

Please mark reply as Helpful/Correct. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

6 REPLIES 6

Hi @Allen Andreas 

Above solution did not worked for me. Can you please help me out.

My use case is as below:

 

1. I have declared the Hidden variable similar to yours.

2. I have a processing script which is getting executed, but I need to check a certain value which I need to pass from my client script and then only Processing script should get executed.

 

Below is what I have tried. I am not sure what mistake I am making here:

 

HTML:

<input type="hidden" id="jvar_answer" name="jvar_answer" value=""/>
<g:dialog_buttons_ok_cancel ok_text="${gs.getMessage('Send')}" ok="actionOK();" cancel="return cancel();"/>

Client Script:

function actionOK() {
    var getMessage = new GlideAjax('SI Name');
    getMessage.addParam('sysparm_name', 'Method Name');
    getMessage.addParam('sysparm_recordID', g_form.getUniqueValue());
    getMessage.getXMLAnswer(getMessageInfo);
}

function getMessageInfo(answer) {
	alert(answer); //getting the alert successfully here

    if (answer != '') {
        if (confirm(getMessage(answer)) == true) {
            gel('jvar_answer').value = "confirmed";
        } else {
            gel('jvar_answer').value = "cancel";
        }

    }
}

Process Script:

gs.info("value of Hidden variable is " + jvar_answer);

 

I am getting the message as blank in the info statement put in processing script.

 

Regards,

Surbhi

Hi Surbhi 

Did you ever get this to work as I am facing the same issue? If your script is working now, could you share your solution. Thanks!