getValue Not Returning Anything in onSubmit Script

Bradford Shelle
Kilo Guru

I'm running through an onSubmit() Catalog Client Script trying to get it to work.

When I run a getValue on a field during an onChange() script, I can see the value of the field I'm looking at no problem. As soon as it's an onSubmit() script though, I don't get a value returned to me.

function onSubmit() {

  //Type appropriate comment here, and begin script below

  var client = g_form.getReference('u_client', getClientEmail);

}

function getClientEmail(client) {

  if (client.email != g_form.getValue('u_client_email')) {

  var email = g_form.getValue('u_client_email');

  alert("Email is: " + email + " and Client is: " + client.sys_id);

  var ga = new GlideAjax('clientEmail');

  ga.addParam('sysparm_name', 'getClientEmail');

  ga.addParam('sysparm_client', client.sys_id);

  ga.addParam('sysparm_email', email);

  ga.getXMLwait();

  }

}

You can see on lines 8 and 9 I'm doing a getValue, and on line 10 I'm just doing a sanity check to make sure that the different parameters I'm passing through to a Script Include actually work.

I've tried poking around to see if there was some conflict with doing a getValue on an onSubmit catalog client script, but nothing was jumping out at me. Does anyone have any ideas?

1 ACCEPTED SOLUTION

You should probably just do it right in the Script of the record producer itself and not as a Client Script.   Are you only wanting to update that record, or are you actually creating another record?   You can use a Record Producer to update records instead and just cancel the "normal" creation of the record.


View solution in original post

11 REPLIES 11

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Is it returning null or just a blank value when you log out the value?


Just blank. Both on the alert and when I log after passing it through to a script include.


One other thing is that if you're already using an ajax call, I would not do the getReference() as you're doing 2 server roundtrips when you can do everything through the ajax call. Srinivas may be right that doing the getValue from inside the callback may be causing some issues.


srinivasthelu
Tera Guru

Hi Bradford,



I suspect getReference CallBack in a onsubmit script is the issue.



I would suggest you to verify the same by adding return false at the end of the onSubmit script




Thanks


Srinivas