I've created an Action under Process for a custom entity new_enrollment. I've created no I/O argument for that action. Now, by using following code snippet I want to run that custom action so that when action is executed a plugin get fired and create a phone call.
But it seems that action is not get executed. Any suggestion or help so that I can get action executed.
function emailOrderDetails(){
var entityId = Xrm.Page.data.entity.getId();
var entityName = "new_enrollment";
var requestName = "new_sendemail";
RunAction(entityId, entityName, requestName);
window.location.reload(true);
}
function RunAction(entityId, entityName, requestName) {
try{
// Creating the request XML for calling the Action
var requestXML = ""
requestXML += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestXML += " <s:Body>";
requestXML += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestXML += " <request xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
requestXML += " <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestXML += " <a:KeyValuePairOfstringanyType>";
requestXML += " <b:key>Target</b:key>";
requestXML += " <b:value i:type=\"a:EntityReference\">";
requestXML += " <a:Id>" + entityId + "</a:Id>";
requestXML += " <a:LogicalName>" + entityName + "</a:LogicalName>";
requestXML += " <a:Name i:nil=\"true\" />";
requestXML += " </b:value>";
requestXML += " </a:KeyValuePairOfstringanyType>";
requestXML += " </a:Parameters>";
requestXML += " <a:RequestId i:nil=\"true\" />";
requestXML += " <a:RequestName>" + requestName + "</a:RequestName>";
requestXML += " </request>";
requestXML += " </Execute>";
requestXML += " </s:Body>";
requestXML += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", GetClientUrl(), false)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestXML);
//Get the Response from the CRM Execute method
//var response = req.responseXML.xml;
}
catch(e){
alert(e.Message);
}
}
function GetClientUrl() {
if (typeof Xrm.Page.context == "object") {
clientUrl = Xrm.Page.context.getClientUrl();
}
var ServicePath = "/XRMServices/2011/Organization.svc/web";
return clientUrl + ServicePath;
}
you are using 2016 which supports WebAPI and its very easy using WebAPI. Below is the working example of calling custom action using JS. I have 2 output variables, one get set by custom action and the other one "ptext" by plugin which i have registered on this Action.
Hope it will solve your problem.
function CallCAction(context) {
var Credit_Limit = Xrm.Page.getAttribute("creditlimit").getValue();
var Credit_hold = Xrm.Page.getAttribute("creditonhold").getValue();
if(Credit_hold !=null && Credit_Limit!=null){
var actionName = "new_Preferred_Check";
var inputParam = {
"Credit_Limit": Credit_Limit,
"Credit_hold": Credit_hold
};
Xrm.Page.ui.setFormNotification("Processing...","INFO","processingFId");
var actionResponse = callPreferredCust(actionName, inputParam);
if (actionResponse != null) {
Xrm.Page.getAttribute("new_preferredcust").setValue(actionResponse.Preferred_Cust);
alert(actionResponse.ptext);
Xrm.Page.ui.clearFormNotification("processingFId");
}
}
}
function callPreferredCust(actionName, inputParam) {
var result = null;
var req = new XMLHttpRequest();
var uri = Xrm.Page.context.getClientUrl() + "/api/data/v8.2/";
try {
req.open("POST",encodeURI(uri+actionName),false);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if(this.readyState==4){
req.onreadystatechange = null;
if(this.status==200){
result = JSON.parse(this.response);
}else{
var err = JSON.parse(this.response).error;
alert(err.message);
}
}
};
req.send(JSON.stringify(inputParam));
return result;
}catch(err){
alert(err.message);
}
}
Related
The error I got from my browser is this:
Uncaught DOMException: Failed to execute 'setRequestHeader' on 'XMLHttpRequest': The object's state must be OPENED.
I put the pics in my github and the json file. I am executing the html file from my workstation. Should I push the html file to github and execute it from there?
This is my Json file pushed to my Github.
{
"events" : [
{ "location" : "San Francisco, CA", "date" : "May 1", "img" :"pic1.jpg"},
{ "location" : "Austin , TX", "date" : "May 15", "img" :"pic2.jpg"},
{ "location" : "New York , NY", "date" : "May 30", "img" :"pic3.jpg"}
]
}
This is my HTML file:
<!DOCTYPE html>
<html>
<body>
<h2>User Account Example</h2>
<script>
var xhr = new XMLHttpRequest();
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
xhr.open("GET", 'https://github.com/${username}/JSON/myjson.json', true);
xhr.send(null);
xhr.onload = function () {
console.log("xhr.status: " + xhr.status);
if (xhr.status === 200) {
console.log("Pineapple Juice");
responseObj = JSON.parse(xhr.responseText);
var newContent = '';
var i;
for (i = 0; i < responseObj.events.length; i++) {
newContent += '<div class="event">';
newContent += '<img src="' + responseObj[i].img + '"';
newContent += 'alt="' + responseObj[i].location + '" />';
newContent += '<p><b>' + responseObj[i].location + '</b><br>';
newContent += responseObj.events[i].date + '</p>';
newContent += '</div>';
}
document.getElementById("myuser").innerHTML = newContent;
}
};
</script>
<div id="myuser"></div>
</body>
</html>
The order is wrong. And Access-Control-Allow-Origin is a response header, this not for requests. Furthermore GET requests cannot have a body, so you don't need the content-type header.
var xhr = new XMLHttpRequest();
xhr.onload = function () {
console.log("xhr.status: " + xhr.status);
if (xhr.status === 200) {
console.log("Pineapple Juice");
responseObj = JSON.parse(xhr.responseText);
var newContent = '';
var i;
for (i = 0; i < responseObj.events.length; i++) {
newContent += '<div class="event">';
newContent += '<img src="' + responseObj[i].img + '"';
newContent += 'alt="' + responseObj[i].location + '" />';
newContent += '<p><b>' + responseObj[i].location + '</b><br>';
newContent += responseObj.events[i].date + '</p>';
newContent += '</div>';
}
document.getElementById("myuser").innerHTML = newContent;
}
};
xhr.open("GET", `https://github.com/${username}/JSON/myjson.json`, true);
// here can you set request headers
xhr.setRequestHeader("Accept", "application/json");
xhr.send(null);
I wrote the following code and the ciso variable is defined and its value is displayed when the code is executed, but when the find_cites function is executed, it shows the Uncaught ReferenceError: x is not defined error.
function find_states(ciso){
var request = new XMLHttpRequest();
request.open('GET', 'https://api.countrystatecity.in/v1/countries/' + ciso + '/states');
request.setRequestHeader('xx', 'xx');
request.onreadystatechange = function () {
if (this.readyState === 4) {
// console.log('Status:', this.status);
// console.log('Headers:', this.getAllResponseHeaders());
// console.log('Body:', this.responseText);
var items2 = JSON.parse(request.responseText);
var output2 = "<select name='state' class='form-select' aria-label='Default select example' style='width: 50%;margin-right: 5%;'>";
// document.getElementById("test").innerHTML = items2;
for(var key in items2){
console.log(items2[key]);
output2+='<option onclick="find_cites(' + ciso + ',' + items2[key].iso2 + ')">' + items2[key].name + '</option>';
}
output2+="</select>";
document.getElementById("state").innerHTML = output2;
// console.log(ciso);
}
};
request.send();
};
function find_cites(ciso,siso){
var request = new XMLHttpRequest();
equest.open('GET', 'https://api.countrystatecity.in/v1/countries/' + ciso + '/states/' + siso + '/cities');
request.setRequestHeader('xx', 'xx');
request.onreadystatechange = function () {
if (this.readyState === 4) {
// console.log('Status:', this.status);
// console.log('Headers:', this.getAllResponseHeaders());
// console.log('Body:', this.responseText);
var items2 = JSON.parse(request.responseText);
var output2 = "<select name='city' class='form-select' aria-label='Default select example' style='width: 50%;margin-right: 5%;'>";
// document.getElementById("test").innerHTML = items2;
for(var key in items2){
console.log(items2[key]);
output2+="<option>" + items2[key].name + "</option>";
}
output2+="</select>";
document.getElementById("city").innerHTML = output2;
// console.log(ciso);
}
};
request.send();
};
You've got possible error here:
equest.open('GET', 'https://api.countrystatecity.in/v1/countries/' + ciso + '/states/' + siso + '/cities');
Should be:
request.open('GET', 'https://api.countrystatecity.in/v1/countries/' + ciso + '/states/' + siso + '/cities');
The ciso variable is a string and must be enclosed in quotation marks ('') when entering the function, but this was ignored when passing data to the function, and the error was related to this point.
The following codes are illustrative:
Old code:
output2+='<option onclick="find_cites(' + ciso + ',' + items2[key].iso2 + ')">' + items2[key].name + '</option>';
New code:
output2+='<option onclick="find_cites(' + "'" + ciso + "'" + ',' + "'" + items2[key].iso2 + "'" + ')">' + items2[key].name + '</option>';
I have changed salesorder entity and create a new status reason in Submitted.
I have added a status reason named PreTransport in submitted state, with value 100000004.
I can go from Active state(pending status reason) to Submitted state(In-Progress status reason) via this request :
var request = ""
request += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
request += " <s:Body>";
request += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
request += " <request i:type=\"b:SetStateRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
request += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>EntityMoniker</c:key>";
request += " <c:value i:type=\"a:EntityReference\">";
request += " <a:Id>" +recordGuid+ "</a:Id>";
request += " <a:LogicalName>salesorder</a:LogicalName>";
request += " <a:Name i:nil=\"true\" />";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>State</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+stateCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " <a:KeyValuePairOfstringanyType>";
request += " <c:key>Status</c:key>";
request += " <c:value i:type=\"a:OptionSetValue\">";
request += " <a:Value>"+statusCode+"</a:Value>";
request += " </c:value>";
request += " </a:KeyValuePairOfstringanyType>";
request += " </a:Parameters>";
request += " <a:RequestId i:nil=\"true\" />";
request += " <a:RequestName>SetState</a:RequestName>";
request += " </request>";
request += " </Execute>";
request += " </s:Body>";
request += "</s:Envelope>";
//send set state request
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/Organization.svc/web", true)
// Responses will return XML. It isn't possible to return JSON.
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
var successCallback = null;
var errorCallback = null;
req.send(request );
But it does not work from In-Progress to PreTransport that are in the same state.
I suppose that it because of permission. Should I set Permission on this new status reason?
If yes How can I do this?
Note that I have CRM 2011 on-premise.
Note: I have tried this code also, but no success.
XrmServiceToolkit.Soap.SetState("salesorder", Xrm.Page.data.entity.getId(), 1, 100000004,false);
Sorry I don't have access to 2011 version. But I tested this below snippet in CRM Rest builder, It works perfectly.
I have created a custom status reason (StatusCode) of value 100000000 : Shipping ready under status (StateCode) of 1 : Submitted. Make sure you are flowing through the allowed transitions like answered here.
var entity = {};
entity.StateCode = {
Value: 1
};
entity.StatusCode = {
Value: 100000000
};
XrmServiceToolkit.Rest.Update("B4B625A1-3789-E811-A967-000D3A1A9407", entity, "SalesOrderSet", function() {
//Success - No Return Data - Do Something
}, function(error) {
Xrm.Utility.alertDialog(error.message);
}, true);
I've checked through the forum and cant seem to get what i need to work.
On the lead entity, when a user creates a new lead a Workflow runs just before to change some lead fields.
I found out this is only possible through javascript and onload in the entity settings.
I've created the Workflow and a JavaScript file and set it to run onload. The Javascript i have used is:
function callworkfow(workflowId, entityId) {
var request =
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<request i:type="b:ExecuteWorkflowRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011 /Contracts" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
<a:Parameters xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<c:key>B3D77337-D5FD-E211-BB05-005056AF0003</c:key>
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">EntityIdValue</c:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<c:key>2EF8C158-182B-444A-A9DF-FF2DC5E44514</c:key>
<c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization /">WorkflowIdValue</c:value>
</a:KeyValuePairOfstringanyType>
</a:Parameters>
<a:RequestId i:nil="true" />
<a:RequestName>ExecuteWorkflow</a:RequestName>
</request>
</Execute>
</s:Body>
</s:Envelope>
var xhr = new XMLHttpRequest();
xhr.open('POST', '/XRMServices/2011/Organization.svc/web', true);
xhr.setRequestHeader('Accept', 'application/xml, text/xml, */*');
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xhr.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute');
xhr.onreadystatechange = function () { alert(xhr.status); };
xhr.send(request);
}
However this fails to load.
If anyone could help me i would be very grateful. Just need the JavaScript to simply load a Workflow. Oh and with cross platform compatibility.
function SetLookupValue(fieldName, id, name, entityType) {
if (fieldName != null) {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = id;
lookupValue[0].name = name;
lookupValue[0].entityType = entityType;
Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
}
}
var ExistingCase = curentUserId = Xrm.Page.context.getUserId();
if (ExistingCase.getValue() != null) {
var ExistingCaseGUID = ExistingCase.getValue()[0].id;
var ExistingCaseName = ExistingCase.getValue()[0].name;
SetLookupValue("new_accountmanager", ExistingCaseGUID, ExistingCaseName, "incident");
}
please check following code, it worked fine for me last time i used it:
if (typeof (SDK) == "undefined")
{ SDK = { __namespace: true }; }
//This will establish a more unique namespace for functions in this library. This will reduce the
// potential for functions to be overwritten due to a duplicate name when the library is loaded.
SDK.Workflow = {
_getServerUrl: function () {
///<summary>
/// Returns the URL for the SOAP endpoint using the context information available in the form
/// or HTML Web resource.
///</summary>
var ServicePath = "/XRMServices/2011/Organization.svc/web";
var serverUrl = "";
if (typeof GetGlobalContext == "function") {
var context = GetGlobalContext();
serverUrl = context.getServerUrl();
}
else {
if (typeof Xrm.Page.context == "object") {
serverUrl = Xrm.Page.context.getServerUrl();
}
else
{ throw new Error("Unable to access the server URL"); }
}
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}
return serverUrl + ServicePath;
},
ExecuteRequest: function () {
var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"b:ExecuteWorkflowRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\" xmlns:b=\"http://schemas.microsoft.com/crm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:c=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>EntityId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">267d4790-e41a-e311-b6a7-3c4a92db481b</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <c:key>WorkflowId</c:key>";
requestMain += " <c:value i:type=\"d:guid\" xmlns:d=\"http://schemas.microsoft.com/2003/10/Serialization/\">a6832cc5-1d82-48f5-a940-e41269726204</c:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>ExecuteWorkflow</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST", SDK.Workflow._getServerUrl(), false)
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestMain);
//work with the response here
var strResponse = req.responseXML.xml;
alert(strResponse.toString());
},
__namespace: true
};
UPDATE:--------------
My previous answer was direct to question. Now providing new answer due to question comments. As it's said in comments workflows can be run only over existing records, but as you said you want to change some field on creation form: record is not saved yet. To do that you must use Xrm object as it is shown below:
function OnLoadingForm() {
var FormType = Xrm.Page.ui.getFormType();
if (FormType != null) {
switch (FormType) {
case 1:
// It's a "create" form
var test = "Mr.";
Xrm.Page.getAttribute("salutation").setValue(test);
break;
case 2:
// It's a "update" form
break;
case 3:
// It's a "readonly" form
break;
case 4:
// It's a "disabled" form
break;
case 6:
// It's a "bulkedit" form
break;
default:
break;
}
}
}
This code works on classic CRM forms (Information forms in customizations). New release may change this. "salutation" is name of field from customizations. Notice that this field change is only on form and will be saved to CRM DB after user clicks Save button.
UPDATE 2:-----------
Due to new circumstances new code snippet:
function OnLoadingForm() {
// Get the current FormType
var FormType = Xrm.Page.ui.getFormType();
if (FormType != null) {
switch (FormType) {
case 1:
// It's a "create" form
var curentUserId = Xrm.Page.context.getUserId();
var serverUrl;
if (Xrm.Page.context.getClientUrl !== undefined) {
serverUrl = Xrm.Page.context.getClientUrl();
} else {
serverUrl = Xrm.Page.context.getServerUrl();
}
var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";
var userRequest = new XMLHttpRequest();
userRequest.open("GET", ODataPath + "/SystemUserSet(guid'" + Xrm.Page.context.getUserId() + "')", false);
userRequest.setRequestHeader("Accept", "application/json");
userRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
userRequest.send();
if (userRequest.status === 200) {
var retrievedUser = JSON.parse(userRequest.responseText).d;
var userFullName = retrievedUser.FullName;
SetLookupValue("new_accountmanager", curentUserId, userFullName, "systemuser");
}
else {
return "error";
}
break;
case 2:
// It's a "update" form
break;
case 3:
// It's a "readonly" form
break;
case 4:
// It's a "disabled" form
break;
case 6:
// It's a "bulkedit" form
break;
default:
break;
}
}
}
function SetLookupValue(fieldName, id, name, entityType) {
if (fieldName != null) {
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = id;
lookupValue[0].name = name;
lookupValue[0].entityType = entityType;
Xrm.Page.getAttribute(fieldName).setValue(lookupValue);
}
}
I have looked at this example but I am still unable to retrieve the JSON Object in the jsp. Here's the code in my MyCalendarController.java class:
public class MyCalendarController implements Controller{
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
if("Add".equals(request.getParameter("action"))){
...
JSONObject jObj = new JSONObject();
jObj.put("test", "Success");
response.getWriter().write(jObj.toString());
...
}
return new ModelAndView("mycalendar", "model", myModel);
}
and here's how I'm trying to retrieve it in jsp but the alert always says 'undefined'
var queryString = "?action=Add";
queryString += "&t=" + title;
queryString += "&sDT=" + stDate + "T" + stHour + ":" + stMin + ":00";
queryString += "&eDT=" + eDate + "T" + eHour + ":" + eMin + ":00";
$.ajax({
type:"GET",
url: "mycalendar.htm" + queryString,
success: function(response){
alert(response.test);
}
});
Note: I am trying to create the JSON Object when the ajax call is made to the class from the jsp. I am new to ajax and javascript so must be doing something wrong... Please help!!!
In the above mentioned code, the response.responseText property is 'undefined'. But I tried it another way:
var ajaxRequest;
try{
ajaxRequest = new XMLHttpRequest();
}catch (e){
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("Your browser broke!");
return false;
}
}
}
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
alert(ajaxRequest.responseText);
alert("test: " + ajaxRequest.test);
}
}
var queryString = "?action=Add";
queryString += "&t=" + title;
queryString += "&sDT=" + stDate + "T" + stHour + ":" + stMin + ":00";
queryString += "&eDT=" + eDate + "T" + eHour + ":" + eMin + ":00";
ajaxRequest.open("GET", "mycalendar.htm" + queryString, true);
ajaxRequest.send(null);
This way I get the ajaxRequest.responseText but the alert("test: " + ajaxRequest.test); still shows undefined
var a = '<%=DropDown.returnList()%>';
var countryObj = JSON.parse(a);
var s = $('#selectCountry');
for(var val in countryObj)
{
$('<option />', {value: val, text: countryObj[val]}).appendTo(s);
}
Try to alert(response.responseText),I am not sure.