How do I pass a value back from Client Side script to be used in the server side script?

jesterize
Tera Contributor

I need to set a UI Action on a form that asks why a certain action was done. I have successfully got the answer, but how do I get it back to server for use? 

I have a form button called Reject, action name RejectAN, with Client box checked, and OnClick set to runClientCode();. Below is my script:

//Client-side 'onclick' funciton
function runClientCode(){
     var answer=prompt('Please provide a justification for rejecting this request.');
     if (answer!=null)
          {
               gsftSubmit(null, g_form.getFormElement(), 'RejectAN');
          }
     else
          {
               return false;
          }
}

//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined'){
     runBusRuleCode();
}

//server-side function
function runBusRuleCode(){
     current.u_approval='rejected';
     current.u_work_notes="Rejected because " + answer;
     current.update();
}

Code runs successfully, but answer is coming back with null. Any ideas?

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

Generally when I do this type of thing, I have to do it by setting the value of a field on the form and then it will be available to you in the server script via current.u_field_name. So you may have to add a new field to your table in order to collect your data. If you don't want it visible, you can hide it with a UI Policy.

and in your client script part, right above the gsftSubmit line, put

g_form.setValue('u_field_name', answer);

View solution in original post

6 REPLIES 6

Jon Barnes
Kilo Sage

Generally when I do this type of thing, I have to do it by setting the value of a field on the form and then it will be available to you in the server script via current.u_field_name. So you may have to add a new field to your table in order to collect your data. If you don't want it visible, you can hide it with a UI Policy.

and in your client script part, right above the gsftSubmit line, put

g_form.setValue('u_field_name', answer);

Allen Andreas
Administrator
Administrator

Hi,

 

From my reading (obviously you followed the guru post) it's that the server side is run independently from the client script portion. So the answer variable wouldn't be defined? Could you try to bring that part up to the client script section? by using g_form.setValue('work_notes', answer); and then doing the rest server side?

Hoping that that would cover both sides for you?

Please mark reply as Helpful/Correct, if applicable. Thanks!


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

Ha, just saw your reply. We both came to the same conclusion - set the work_notes using g_form on the client side.

Brent

😉


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