function retrieveDemographics(){
try{
//debugger;
var eligibility;
var veteran;
var unemployable;
var svcCI;
var percentage;
var sensitivityFlag;
var add1;
var addt1;
var add2;
var addt2;
var add3;
var addt3;
var city;
var tcity;
var state;
var tstate;
var zip;
var tzip;
var country;
var tcountry;
var key = Xrm.Page.getAttribute("tri_veteranid").getValue();
//var key = "1003100560V020099";


var ret;
var request ="https://qacrmdac.np.crm.vrm.vba.DNS   /WebParts/api/eesummary/1.0/xml/ftpCRM/000000"+key+"000000";
var query = new XMLHttpRequest();
query.open('GET', request, true);
query.onreadystatechange = function(){
	if (query.readyState == 4 && query.status==200){
		if (query.responseXML.childNodes[0].childNodes.length === 0){
			
			return;
		}
ret = query.responseXML.getElementsByTagName("ratedDisability")[0];
		eligibility = query.responseXML.getElementsByTagName("primaryEligibility")[0].childNodes[2].childNodes[0].data;
		//veteran = query.responseXML.getElementsByTagName("veteran")[0].childNodes[0].nodeValue;
		unemployable = query.responseXML.getElementsByTagName("unemployable")[0].childNodes[0].nodeValue;
		svcCI = query.responseXML.getElementsByTagName("serviceConnectedIndicator")[0].childNodes[0].nodeValue;
                if(svcCI === "true"){
		percentage = query.responseXML.getElementsByTagName("ratedDisability")[0].childNodes[0].childNodes[0].nodeValue;
}
		sensitivityFlag = query.responseXML.getElementsByTagName("sensitivityInfo")[0].childNodes[0].childNodes[0].nodeValue;
		var adds=query.responseXML.getElementsByTagName("addresses");
		var perm;
                var temp = null;
		for (i=0; i<adds[0].childNodes.length; i++){
			if (adds[0].childNodes[i].childNodes[0].childNodes[0].nodeValue === "Permanent"){
				perm = i;
				
			}
			
		}

for (i=0; i<adds[0].childNodes.length; i++){
			if (adds[0].childNodes[i].childNodes[0].childNodes[0].nodeValue === "Temporary"){
				temp = i;
				
			}
			
		}
if (perm !== null){
		var pa= query.responseXML.getElementsByTagName("addresses")[0].childNodes[perm];
}
if(temp !== null){
        var ta = query.responseXML.getElementsByTagName("addresses")[0].childNodes[temp];
}

		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "line1"){
				add1 = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		if(temp !==null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "line1"){
				addt1 = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "line2"){
				add2 = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		if(temp !== null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "line2"){
				addt2 = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "line3"){
				add3 = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		if(temp !== null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "line3"){
				addt3 = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "city"){
				city = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}

		if(temp){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "city"){
				tcity = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "state"){
				state = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		if(temp !== null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "state"){
				tstate = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "zip"){
				zip = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		if(temp !== null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "zip"){
				tzip = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
		}
		for (i=0; i<pa.childNodes.length; i++){
			if (pa.childNodes[i].nodeName === "country"){
				country = pa.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
if(temp!== null){
for (i=0; i<ta.childNodes.length; i++){
			if (ta.childNodes[i].nodeName === "country"){
				tcountry = ta.childNodes[i].childNodes[0].nodeValue;
			}
			
		}
}

		Xrm.Page.getAttribute("ftp_primaryeligibilitycode").setValue(eligibility);
		if(veteran === "true"){
		Xrm.Page.getAttribute("ftp_patienttype").setValue("veteran");
		}
		else{
			Xrm.Page.getAttribute("ftp_patienttype").setValue("Non-Veteran");
		}
		Xrm.Page.getAttribute("ftp_unemployable").setValue(unemployable);
		if(svcCI === "true"){
			Xrm.Page.getAttribute("ftp_serviceconnected").setValue(true);
		}
		else{
			Xrm.Page.getAttribute("ftp_serviceconnected").setValue(false);
		}
		if (percentage != null){
			Xrm.Page.getAttribute("ftp_scpercent").setValue(percentage);
		}
		if (sensitivityFlag === "true"){
		Xrm.Page.getAttribute("ftp_sensitiveveteran").setValue(true);
		}
		else{
			Xrm.Page.getAttribute("ftp_sensitiveveteran").setValue(false);
			
		}
if(add1 !== null){
		Xrm.Page.getAttribute("address1_line1").setValue(add1);
}
if(addt1 !== null){
		Xrm.Page.getAttribute("address2_line1").setValue(addt1);
}
if(add2 !== null){
		Xrm.Page.getAttribute("address1_line2").setValue(add2);
}
if(addt2 !== null){
		Xrm.Page.getAttribute("address2_line2").setValue(addt2);
}
if(add3 !== null){
		Xrm.Page.getAttribute("address1_line3").setValue(add3);
}
if(addt3 !== null){
		Xrm.Page.getAttribute("address2_line3").setValue(addt3);
}
if(city !== null){
		Xrm.Page.getAttribute("address1_city").setValue(city);
}
if(tcity !== null){
		Xrm.Page.getAttribute("address2_city").setValue(tcity);
}
if(state !== null){
		Xrm.Page.getAttribute("address1_stateorprovince").setValue(state);
}
if(tstate !== null){
		Xrm.Page.getAttribute("address2_stateorprovince").setValue(tstate);
}
if(country !== null){
		Xrm.Page.getAttribute("address1_country").setValue(country);
}
if(tcountry !== null){
		Xrm.Page.getAttribute("address2_country").setValue(tcountry);
}
if(zip !== null){
		Xrm.Page.getAttribute("address1_postalcode").setValue(zip);
}
if(tzip !== null){
		Xrm.Page.getAttribute("address2_postalcode").setValue(tzip);
}
var address1_compositeValue = Xrm.Page.getAttribute("address1_composite").getValue();
var address1_line1 = Xrm.Page.getAttribute("address1_line1").getValue();
  var address1_line2 = Xrm.Page.getAttribute("address1_line2").getValue();
  var address1_line3 = Xrm.Page.getAttribute("address1_line3").getValue();
  var address1_city = Xrm.Page.getAttribute("address1_city").getValue();
  var address1_stateorprovince = Xrm.Page.getAttribute("address1_stateorprovince").getValue();
  var address1_postalcode = Xrm.Page.getAttribute("address1_postalcode").getValue();
  var address1_country = Xrm.Page.getAttribute("address1_country").getValue();

  // Achieve equivalent formatting
  //address1_line1
  //address1_line2
  //address1_line3
  //address1_city, address1_stateorprovince address1_postalcode
  //address1_country

  var addressText = "";
  if (address1_line1 != null) {
   addressText += address1_line1 + "\n";
  }
  if (address1_line2 != null) {
   addressText += address1_line2 + "\n";
  }
  if (address1_line3 != null) {
   addressText += address1_line3 + "\n";
  }
  if (address1_city != null) {
   addressText += address1_city + ", ";
  }
  if (address1_stateorprovince != null) {
   addressText += address1_stateorprovince + " ";
  }
  if (address1_postalcode != null) {
   addressText += address1_postalcode + "\n";
  }
  addressText += address1_country;

  Xrm.Page.getAttribute("address1_composite").setValue(addressText);

var address2_compositeValue = Xrm.Page.getAttribute("address2_composite").getValue();
var address2_line1 = Xrm.Page.getAttribute("address2_line1").getValue();
  var address2_line2 = Xrm.Page.getAttribute("address2_line2").getValue();
  var address2_line3 = Xrm.Page.getAttribute("address2_line3").getValue();
  var address2_city = Xrm.Page.getAttribute("address2_city").getValue();
  var address2_stateorprovince = Xrm.Page.getAttribute("address2_stateorprovince").getValue();
  var address2_postalcode = Xrm.Page.getAttribute("address2_postalcode").getValue();
  var address2_country = Xrm.Page.getAttribute("address2_country").getValue();

  // Achieve equivalent formatting
  //address1_line1
  //address1_line2
  //address1_line3
  //address1_city, address1_stateorprovince address1_postalcode
  //address1_country

  var address2Text = "";
  if (address2_line1 != null) {
   address2Text += address2_line1 + "\n";
  }
  if (address2_line2 != null) {
   address2Text += address2_line2 + "\n";
  }
  if (address2_line3 != null) {
   address2Text += address2_line3 + "\n";
  }
  if (address2_city != null) {
   address2Text += address2_city + ", ";
  }
  if (address2_stateorprovince != null) {
   address2Text += address2_stateorprovince + " ";
  }
  if (address1_postalcode != null) {
   address2Text += address2_postalcode + "\n";
  }
  address2Text += address2_country;

  Xrm.Page.getAttribute("address2_composite").setValue(address2Text);

Xrm.Page.data.entity.save();

	}
};
query.send(request);
}
catch(e){
alert(e);
}
}