Split an Array from GlideAjax on the Client Side

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2012 02:43 PM
Hello,
I'm fairly new to GlideAjax and I can't figure out how to pass an array from a Script Include via GA into a Client Script so that I can split out the values in my array to set fields on the form.
My script include is successfully logging the array - e.g.: MyArray fc3e0ba67b549400341bc676e84d4de2,No,Yes
What I can't figure out is how to get my client script to split out the values in the array so I can set form fields with the values.
I've tried several ways but my alert(answer) returns this: org.mozilla.javascript.NativeArray@xxxxxx (where xxxxxx is some random mix of numbers and letters which changes every time. Can i not pass a simple string array? Does the array need to be in XML format or something?
What is the correct way to process the array on the Client Side? Here's my current script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading){
return;
}
if(newValue){
var major = g_form.getReference('parent');
var ga = new GlideAjax('getParentFields');
ga.addParam('sysparm_name','ParentFields');
ga.addParam('sysparm_sys_id', major.sys_id);
ga.getXML(getFieldsParce);
}
function getFieldsParce(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var resp = answer.split(',');
var bs = resp.split[0];
var ans1 = resp.split[1];
var ans2 = resp.split[2];
//set values on form with array results...
g_form.setValue('u_business_service', bs);
g_form.setValue('u_answer_1', ans1);
g_form.setValue('u_answer_2', ans2);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2014 11:17 AM
Thanks for mentioning this Geoff. It looks like the community migration might have changed the script just enough to break it. You just need to change the following lines (these two blocks mentioned in the post). Change <i> to [i].
Sad:
var name = favorites<i>.getAttribute("name");
var value = favorites<i>.getAttribute("value");
Happy:
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
It doesn't look like I can edit the original post but I'm looking into getting it corrected.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-21-2012 02:23 PM
You can also checkout my latest blog post on returning multiple values with GlideAjax
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-29-2014 12:49 PM