- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 07:48 PM
I have wrote a script include for an array outcome. I am calling the same script include through a client script. What I need is to get an alert/pop-up alert to display the result of the same array. How can that be achieved?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 04:11 AM
Hi Kunal,
Instead of alerting it in the loop just add it and display it after the loop's finished:
- function _processResponse(response) {
- var userAttributes = response.responseXML.getElementsByTagName("userAttributes"),
- sStringToAdd = "",
- sAnswer = "";
- for (var i=0; i<userAttributes.length; i++){
- sStringToAdd = i<userAttributes.length - 1 ? userAttributes[i].getAttribute("value") + "," : userAttributes[i].getAttribute("value") + "";
- sAnswer += sStringToAdd;
- }
- alert(sAnswer);
- }
Cheers
Greg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2015 09:17 PM
Hi Kunal,
I put together a simple example of how it could be done. I hope it's helpful
On the script include
var getAttributesInArray = Class.create();
getAttributesInArray.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getAttributes: function() {
var arrAttributes = [];
// ..
// Here goes the lines of code which populate your array
//
if (arrAttributes.length > 0)
{
for (var i=0; i<arrAttributes.length; i++){
this._addAttribute("attribute",arrAttributes[i].toString());
}
}
},
_addAttribute : function(name, value)
{
var userAttributes = this.newItem("userAttributes");
userAttributes.setAttribute("name", name);
userAttributes.setAttribute("value", value);
}
});
On the client side:
function onChange(control, oldValue, newValue, isLoading) {
var ga = new GlideAjax('getAttributesInArray');
ga.addParam('sysparm_name','getAttributes');
ga.getXML(_processResponse);
function _processResponse(response) {
var userAttributes = response.responseXML.getElementsByTagName("userAttributes");
for (var i=0; i<userAttributes.length; i++){
alert(userAttributes[i].getAttribute("value"));
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:17 AM
Hi Berny,
Thank you so much for your reply. It is really helpful.
Now I am facing the issue is: if there are two values in the array what I am returning from the script include, it is showing two alerts one after another. First alert with the first value then second alert with the second value.
example:
Alert(INC0000001)
Alert(INC0000001)
I want only one alert to show and the values will be ',' separated.
So I want the result like:
alert(INC0000001,INC0000002)
Please help me in achieving the result like this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:28 AM
When you are pushing the values in a array in script include, before returning the value, add a toString() to the array variable.
return arrayvariable.toString();
Now, you will have the comma separated value at the client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2015 02:32 AM
Yes toString is added before only. I am trying to comma separate the result at the client side now.
Any help will be appreciated.