var city;
var result = function () {
city = "Moscow";
}
result();
alert(city);function cityfromevent()
{
var city;
var event = Xrm.Page.getAttribute("new_eventid").getValue()[0].id;
event = event.replace('{', ' ').replace('}', ' ');
var oDataPath = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
var filter = "/New_EventSet?$select=New_CityId,New_EventId&$filter=New_EventId eq guid'" + event + "'";
var odataSelect = oDataPath + filter;
var retrieveRecordsReq = new XMLHttpRequest();
retrieveRecordsReq.open("GET", oDataPath + filter, true);
retrieveRecordsReq.setRequestHeader("Accept", "application/json");
retrieveRecordsReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
retrieveRecordsReq.onreadystatechange = function ()
{
if (this.readyState == 4)
{
if (this.status == 200)
{
var retrievedRecords = JSON.parse(retrieveRecordsReq.responseText).d;
if (retrievedRecords.results.length > 0)
{
var result = retrievedRecords.results[0];
city = result.New_CityId.Id;
}
}
}
retrieveRecordsReq.send();
}
alert(city);
}
// Инициализировать переменную значением undefined
var city;
// Определить функцию result
var result = function () {
// присвоить переменной значение
city = "Moscow";
}
// Вызвать функцию alert с параметром city
alert(city);