- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 07:30 AM
I need to get the answer from my GlideAjax script and use this answer in other if statements in my client script. How do I do this?
Simple GlideAjax:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:44 AM - edited 10-27-2023 08:45 AM
Hi @kemmy1 ,
Why don't u define your logic in your existing function where u receiving response from GlideAjax? Something like below
var ga = new GlideAjax('asu_GetLocationData');
ga.addParam('sysparm_name', 'getCampus');
ga.addParam('sysparm_buildingid', g_form.getValue("u_building"));
ga.getXMLAnswer(updateCampus);
}
function updateCampus(answer) {
var clearvalue; // Stays Undefined
if (answer) {
var returneddata = JSON.parse(answer);
g_form.setValue("campus", returneddata.sys_id, returneddata.name);
} else {
g_form.setValue("campus", clearvalue);
}
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:39 AM
That did not work as well. 😞
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:44 AM - edited 10-27-2023 08:45 AM
Hi @kemmy1 ,
Why don't u define your logic in your existing function where u receiving response from GlideAjax? Something like below
var ga = new GlideAjax('asu_GetLocationData');
ga.addParam('sysparm_name', 'getCampus');
ga.addParam('sysparm_buildingid', g_form.getValue("u_building"));
ga.getXMLAnswer(updateCampus);
}
function updateCampus(answer) {
var clearvalue; // Stays Undefined
if (answer) {
var returneddata = JSON.parse(answer);
g_form.setValue("campus", returneddata.sys_id, returneddata.name);
} else {
g_form.setValue("campus", clearvalue);
}
}
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:47 AM - edited 10-27-2023 09:53 AM
I guess I could do that. I just have it nice and neat (my code) so now part of it will need to be in that response function. I'm just surprised I can't get the response data out of the function.
Plus I have an if statement to start the whole client script (if status = completed) and I can't add that function under that if statement.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 12:50 PM
A free course I took when I was starting with javascript:
https://www.codecademy.com/catalog/language/javascript
To learn about javascript, if you continue to use javascript in your work.