- 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 07:43 AM
Hi,
I'm guessing you see the "response:" message, and not the :student2:" message. If so, that would be because you declare 'student2' in the function, and it is not valid outside of the function. What do you want to do with the 'response' there?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:33 AM
I want to take the response (it's a yes or no) and use it in other If statements in my client script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:04 AM
Hi @kemmy1
You can try declaring variable outside and then assign value
var student2;
var getStudent = new GlideAjax('<glideAjax');
getStudent.addParam('sysparm_name', 'isLawStudent');
getStudent.getXMLAnswer(getStudentResult);
function getStudentResult(response) {
g_form.addInfoMessage("response: " + response);
student2 = response;
}
g_form.addInfoMessage("student2: " + student2);
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-27-2023 08:26 AM