- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 07:44 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 11:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 09:20 AM
Yeah once you put it that way Brad I was way overthinking it. Only needed to make one call to the server instead of two, I just forgot I can grab the sys_id of my reference field and throw a .toString() at the end of it and just pass it through with the Ajax call.
function onSubmit() {
var email = g_form.getValue('u_client_email');
var client = g_form.getValue('u_client').toString();
alert("Email is: " + email + " and Client is: " + client);
var ga = new GlideAjax('clientEmail');
ga.addParam('sysparm_name', 'getClientEmail');
ga.addParam('sysparm_client', client);
ga.addParam('sysparm_email', email);
ga.getXML(Finished);
}
function Finished(response) {
return;
}
It works now (though I'm sure tweaking could be done to make it better)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 11:26 AM
The onSubmit Client Script is one of the very few places where you really do not need nor even want to use Ajax calls.
Your users are not waiting to do anything else so there's really no need to give them back control right away. And using Ajax may actually mess up your expected results if not done properly because the result may come back after your script ends.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 11:36 AM
Here, guess I should give a more complete picture as to what I'm doing. This is the script include that is being called from the onSubmit client script.
var clientEmail = Class.create();
clientEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getClientEmail: function() {
var user = this.getParameter('sysparm_client');
var email = this.getParameter('sysparm_email');
//gs.log("User: " + user + ". Email: " + email, "BLSTEST");
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', user);
gr.query();
while(gr.next()) {
gr.email = email;
gr.update();
}
return;
}
});
I'm trying to update a record being referenced in the record producer. In reality, I don't need to wait for a response from the Ajax call, granted that's a pretty haphazard method. I just kind of scratched my brain a bit at how to utilize a client script to update another record and this is what I could come up with.
Totally open to a better method on how to get this done.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 11:49 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2015 11:59 AM
Excuse me while I hit my head against my desk for a few minutes. I can't believe I forgot about this! So much easier. Thank you Jim!