Hi
I'm calling the function in the file 'function.txt':
function QuartersPaymentValidation() {
//debugger;
var att_property, att_entityName, att_propertyEntityName, propertyType, quarter, previousquarter, year;
propertyType = Xrm.Page.getAttribute("gits_property_type").getValue();
if (propertyType != null) {
if (propertyType == 449930000) {
att_property = Xrm.Page.getAttribute("gits_hotel");
att_entityName = "gits_hotelid";
att_propertyEntityName = "gits_hotel";
}
else if (propertyType == 449930001) {
att_property = Xrm.Page.getAttribute("gits_apartment");
att_entityName = "gits_apartmentid";
att_propertyEntityName = "gits_apartment";
}
else if (propertyType == 449930002) {
att_property = Xrm.Page.getAttribute("gits_restaurant");
att_entityName = "gits_restaurantid";
att_propertyEntityName = "gits_restaurant";
}
else if (propertyType == 449930003) {
att_property = Xrm.Page.getAttribute("gits_othersid");
att_entityName = "gits_othersid";
}
if (att_property.getValue() != null) {
var sFetch = "<fetch mapping='logical'>" +
"<entity name='gits_payment_record'>" +
"<attribute name='gits_paymentamount' />" +
"<attribute name='gits_payment_reason' />" +
"<attribute name='gits_quarteryear' />" +
"<order attribute='gits_quarteryear' descending='true' />" +
"<order attribute='gits_payment_reason' descending='true' />" +
"<filter type='and'>" +
"<condition attribute='statuscode' operator='eq' value='2'/>" +
"<condition attribute='" + att_entityName + "' operator='eq' value='" + att_property.getValue()[0].id + "'/>" +
"<condition attribute='gits_payment_reason' operator='in'>" +
"<value>449930005</value>" +
"<value>449930006</value>" +
"<value>449930007</value>" +
"<value>449930008</value>" +
"</condition>" +
"</filter>" +
"</entity>" +
"</fetch>";
_oService = new FetchUtil(_sOrgName, _sServerUrl);
var res = _oService.Fetch(sFetch);
if (res.length > 0) {
Xrm.Page.ui.controls.get("gits_quarter").setDisabled(false);
Xrm.Page.ui.controls.get("gits_year").setDisabled(false);
quarter = res[0].attributes["gits_payment_reason"].value - 5;
year = res[0].attributes["gits_quarteryear"].value;
if (quarter == 449930003) {
year = parseInt(year) + 1;
quarter = 449930000;
Xrm.Page.getAttribute("gits_quarter").setValue(quarter);
Xrm.Page.getAttribute("gits_previousquarter").setValue(quarter.toString());
Xrm.Page.getAttribute("gits_year").setValue(year);
Xrm.Page.getAttribute("gits_previousyear").setValue(year.toString());
QuarterAndYearsSummary();
}
else if (quarter == 449930002) {
quarter = 449930003;
Xrm.Page.getAttribute("gits_quarter").setValue(quarter);
Xrm.Page.getAttribute("gits_previousquarter").setValue(quarter.toString());
Xrm.Page.getAttribute("gits_year").setValue(year);
Xrm.Page.getAttribute("gits_previousyear").setValue(year.toString());
QuarterAndYearsSummary();
}
else if (quarter == 449930001) {
quarter = 449930002;
Xrm.Page.getAttribute("gits_quarter").setValue(quarter);
Xrm.Page.getAttribute("gits_previousquarter").setValue(quarter.toString());
Xrm.Page.getAttribute("gits_year").setValue(year);
Xrm.Page.getAttribute("gits_previousyear").setValue(year.toString());
QuarterAndYearsSummary();
}
else if (quarter == 449930000) {
quarter = 449930001;
Xrm.Page.getAttribute("gits_quarter").setValue(quarter);
Xrm.Page.getAttribute("gits_previousquarter").setValue(quarter.toString());
Xrm.Page.getAttribute("gits_year").setValue(year);
Xrm.Page.getAttribute("gits_previousyear").setValue(year.toString());
QuarterAndYearsSummary();
}
}
else {
var selectedYesr = new Date().getFullYear().toString(10).substring(2, 4);
if (att_property.getValue() != null) {
var sFetchWorkdate = "<fetch mapping='logical'>" +
"<entity name='" + att_propertyEntityName + "'>" +
"<attribute name='gits_work_date' />" +
"<filter type='and'>" +
"<condition attribute='" + att_entityName + "' operator='eq' value='" +
att_property.getValue()[0].id + "'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
_oService = new FetchUtil(_sOrgName, _sServerUrl);
var res = _oService.Fetch(sFetchWorkdate);
//alert(sFetchWorkdate);
//alert(res);
//alert(res.length);
if (res.length > 0) {
//alert(res[0].attributes["gits_work_date"].value);
var selectedYesr = res[0].attributes["gits_work_date"].value.toString(10).substring(2, 4);
//alert(selectedYesr);
selectedYesr = "4499300" + selectedYesr;
//alert(selectedYesr);
var workdatemonth = res[0].attributes["gits_work_date"].value.toString(10).substring(5, 7);
//alert(workdatemonth);
if( workdatemonth =='01' || workdatemonth =='02' || workdatemonth =='03' ){
Xrm.Page.getAttribute("gits_quarter").setValue(449930000);
Xrm.Page.getAttribute("gits_previousquarter").setValue("449930000");
}
else if(workdatemonth =='04' || workdatemonth =='05' || workdatemonth =='06'){
Xrm.Page.getAttribute("gits_quarter").setValue(449930001);
Xrm.Page.getAttribute("gits_previousquarter").setValue("449930001");
}
else if (workdatemonth =='07' || workdatemonth =='08' || workdatemonth =='09'){
Xrm.Page.getAttribute("gits_quarter").setValue(449930002);
Xrm.Page.getAttribute("gits_previousquarter").setValue("449930002");
}
else {
Xrm.Page.getAttribute("gits_quarter").setValue(449930003);
Xrm.Page.getAttribute("gits_previousquarter").setValue("449930003");
}
Xrm.Page.ui.controls.get("gits_quarter").setDisabled(false);
Xrm.Page.ui.controls.get("gits_year").setDisabled(false);
Xrm.Page.getAttribute("gits_year").setValue(selectedYesr);
Xrm.Page.getAttribute("gits_previousyear").setValue(selectedYesr);
QuarterAndYearsSummary();
}
}
}
}
}
}
That function is refering to the functions in the CRUD.js file:
///<reference path="..\XrmPage-vsdoc.js"/>
var _oService;
var _sOrgName = "";
var _sServerUrl = Xrm.Page.context.getServerUrl();
var showError = true;
function updateRecordById(prmEntityName, prmRecordId, prmFields, prmValues) {
var entityName = prmEntityName;
var recordId = prmRecordId;
var fields = prmFields.split(",");
var values = prmValues.split(",");
var attributesTags = "";
var authenticationHeader = GenerateAuthenticationHeader();
for (var i = 0; i < fields.length; i++) {
attributesTags += "<" + fields[i] + ">" + values[i] + "</" + fields[i] + ">";
}
// Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='schemas.xmlsoap.org/.../envelope'" +
" xmlns:xsi='www.w3.org/.../XMLSchema-instance'" +
" xmlns:xsd='www.w3.org/.../XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Update xmlns='schemas.microsoft.com/.../WebServices'>" +
"<entity xsi:type='" + entityName + "'>" + //entity name
attributesTags + //"<address1_line1>" + newAddressLine1 + "</address1_line1>" +
"<" + entityName + "id>" + recordId + "</" + entityName + "id>" +
"</entity>" +
"</Update>" +
"</soap:Body>" +
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Update");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
}
}
function RetrieveEntityById(prmEntityName, prmEntityId, prmEntityColumns) {
var resultXml, errorCount, msg, xmlHttpRequest, arrayEntityColumns, xmlEntityColumns;
arrayEntityColumns = prmEntityColumns.split(",");
for (var i = 0; i < arrayEntityColumns.length; i++) {
xmlEntityColumns += "<q1:Attribute>" + arrayEntityColumns[i] + "</q1:Attribute>";
}
var authenticationHeader = Xrm.Page.context.getAuthenticationHeader();
//Prepare the SOAP message.
var xml = "<?xml version='1.0' encoding='utf-8'?>" +
"<soap:Envelope xmlns:soap='schemas.xmlsoap.org/.../envelope'" +
" xmlns:xsi='www.w3.org/.../XMLSchema-instance'" +
" xmlns:xsd='www.w3.org/.../XMLSchema'>" +
authenticationHeader +
"<soap:Body>" +
"<Retrieve xmlns='schemas.microsoft.com/.../WebServices'>" +
"<entityName>" + prmEntityName + "</entityName>" +
"<id>" + prmEntityId + "</id>" +
"<columnSet xmlns:q1='schemas.microsoft.com/.../Query' xsi:type='q1:ColumnSet'>" +
"<q1:Attributes>" +
xmlEntityColumns +
"</q1:Attributes>" +
"</columnSet>" +
"</Retrieve></soap:Body></soap:Envelope>";
//call function to create Soap Request to ms crm webservice
xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.setRequestHeader("responseType", 'msxml-document');//Hasan Kadhem, Mohd Ebrahim Jan 28 2016
xmlHttpRequest.send(xml);
resultXml = xmlHttpRequest.responseXML;
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0 && showError) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert("Error Message : " + msg);
}
else {
return resultXml;
}
}
function CreateRecord(entityName, fields) {
try {
var resultArray = new Array();
var attributesList = '';
for (var i = 0; i < fields.length; i++)
attributesList += "<" + fields[i].SchemaName + ">" + fields[i].Value + "</" + fields[i].SchemaName + ">";
var xml = "<Create xmlns='schemas.microsoft.com/.../WebServices'><entity xsi:type='" + entityName + "'>" + attributesList + "</entity></Create>";
var resultXml = CallCrmService(xml, 'Create');
if (resultXml) {
var newid = resultXml.selectSingleNode('//CreateResult').nodeTypedValue;
return newid;
}
}
catch (err) {
alert("Error:" + err.Message);
}
return null;
}
function CallCrmService(soapBody, method) {
try {
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", '/mscrmservices/2007/CrmService.asmx', false);
xmlHttpRequest.setRequestHeader("SOAPAction", 'schemas.microsoft.com/.../WebServices' + method);
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
var xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<soap:Envelope xmlns:soap=\'schemas.xmlsoap.org/.../envelope\' xmlns:xsi=\'www.w3.org/.../XMLSchema-instance\' xmlns:xsd=\'www.w3.org/.../XMLSchema\'>" +
GenerateAuthenticationHeader() + "<soap:Body>" + soapBody + "</soap:Body></soap:Envelope>";
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var resultXml = xmlHttpRequest.responseXML;
var errorCount = resultXml.selectNodes('//error').length;
if (errorCount != 0) {
var msg = resultXml.selectSingleNode('//description').nodeTypedValue;
alert(msg);
return null;
}
return resultXml;
}
catch (err) {
}
return null;
}
// Make Struct
function MakeStruct(names) {
var names = names.split(' ');
var count = names.length;
function constructor() {
for (var i = 0; i < count; i++) {
this[names[i]] = arguments[i];
}
}
return constructor;
}
// CRM Field Struct
var CRMField = MakeStruct("SchemaName Value");
/////////////Fetch XML
var XMLHTTPSUCCESS = 200;
var XMLHTTPREADY = 4;
function FetchUtil(sOrg, sServer) {
this.org = sOrg;
this.server = sServer;
if (sOrg == null) {
if (typeof (ORG_UNIQUE_NAME) != "undefined") {
this.org = ORG_UNIQUE_NAME;
}
}
if (sServer == null) {
this.server = window.location.protocol + "//" + window.location.host;
}
}
FetchUtil.prototype._ExecuteRequest = function (sXml, sMessage, fInternalCallback, fUserCallback) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", this.server + "/XRMServices/2011/Organization.svc/web", (fUserCallback != null));
xmlhttp.setRequestHeader("Accept", "application/xml, text/xml, */*");
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "schemas.microsoft.com/.../Execute");
if (fUserCallback != null) {
//asynchronous: register callback function, then send the request.
var crmServiceObject = this;
xmlhttp.onreadystatechange = function () {
fInternalCallback.call(crmServiceObject, xmlhttp, fUserCallback)
};
xmlhttp.send(sXml);
} else {
//synchronous: send request, then call the callback function directly
xmlhttp.send(sXml);
return fInternalCallback.call(this, xmlhttp, null);
}
}
FetchUtil.prototype._HandleErrors = function (xmlhttp) {
/// <summary>(private) Handles xmlhttp errors</summary>
if (xmlhttp.status != XMLHTTPSUCCESS) {
var sError = "Error: " + xmlhttp.responseText + " " + xmlhttp.statusText;
//alert(sError);
return true;
} else {
return false;
}
}
FetchUtil.prototype.Fetch = function (sFetchXml, fCallback) {
/// <summary>Execute a FetchXml request. (result is the response XML)</summary>
/// <param name="sFetchXml">fetchxml string</param>
/// <param name="fCallback" optional="true" type="function">(Optional) Async callback function if specified. If left null, function is synchronous </param>
var request = "<s:Envelope xmlns:s=\"schemas.xmlsoap.org/.../envelope\">";
request += "<s:Body>";
request += '<Execute xmlns="schemas.microsoft.com/.../Services">' +
'<request i:type="b:RetrieveMultipleRequest" ' +
' xmlns:b="schemas.microsoft.com/.../Contracts" ' +
' xmlns:i="www.w3.org/.../XMLSchema-instance">' +
'<b:Parameters xmlns:c="schemas.datacontract.org/.../System.Collections.Generic">' +
'<b:KeyValuePairOfstringanyType>' +
'<c:key>Query</c:key>' +
'<c:value i:type="b:FetchExpression">' +
'<b:Query>';
request += CrmEncodeDecode.CrmXmlEncode(sFetchXml);
request += '</b:Query>' +
'</c:value>' +
'</b:KeyValuePairOfstringanyType>' +
'</b:Parameters>' +
'<b:RequestId i:nil="true"/>' +
'<b:RequestName>RetrieveMultiple</b:RequestName>' +
'</request>' +
'</Execute>';
request += '</s:Body></s:Envelope>';
return this._ExecuteRequest(request, "Fetch", this._FetchCallback, fCallback);
}
FetchUtil.prototype._FetchCallback = function (xmlhttp, callback) {
///<summary>(private) Fetch message callback.</summary>
//xmlhttp must be completed
if (xmlhttp.readyState != XMLHTTPREADY) {
return;
}
//check for server errors
if (this._HandleErrors(xmlhttp)) {
return;
}
var sFetchResult = xmlhttp.responseXML.selectSingleNode("//a:Entities").xml;
var resultDoc = new ActiveXObject("Microsoft.XMLDOM");
resultDoc.async = false;
resultDoc.loadXML(sFetchResult);
//parse result xml into array of jsDynamicEntity objects
var results = new Array(resultDoc.firstChild.childNodes.length);
for (var i = 0; i < resultDoc.firstChild.childNodes.length; i++) {
var oResultNode = resultDoc.firstChild.childNodes[i];
var jDE = new jsDynamicEntity();
var obj = new Object();
for (var j = 0; j < oResultNode.childNodes.length; j++) {
switch (oResultNode.childNodes[j].baseName) {
case "Attributes":
var attr = oResultNode.childNodes[j];
for (var k = 0; k < attr.childNodes.length; k++) {
// Establish the Key for the Attribute
var sKey = attr.childNodes[k].firstChild.text;
var sType = "";
// Determine the Type of Attribute value we should expect
for (var l = 0; l < attr.childNodes[k].childNodes[1].attributes.length; l++) {
if (attr.childNodes[k].childNodes[1].attributes[l].baseName == 'type') {
sType = attr.childNodes[k].childNodes[1].attributes[l].text;
}
}
switch (sType) {
case "a:OptionSetValue":
var entOSV = new jsOptionSetValue();
entOSV.type = sType;
entOSV.value = attr.childNodes[k].childNodes[1].text;
obj[sKey] = entOSV;
break;
case "a:EntityReference":
var entRef = new jsEntityReference();
entRef.type = sType;
entRef.guid = attr.childNodes[k].childNodes[1].childNodes[0].text;
entRef.logicalName = attr.childNodes[k].childNodes[1].childNodes[1].text;
entRef.name = attr.childNodes[k].childNodes[1].childNodes[2].text;
obj[sKey] = entRef;
break;
default:
var entCV = new jsCrmValue();
entCV.type = sType;
entCV.value = attr.childNodes[k].childNodes[1].text;
obj[sKey] = entCV;
break;
}
}
jDE.attributes = obj;
break;
case "Id":
jDE.guid = oResultNode.childNodes[j].text;
break;
case "LogicalName":
jDE.logicalName = oResultNode.childNodes[j].text;
break;
case "FormattedValues":
var foVal = oResultNode.childNodes[j];
for (var k = 0; k < foVal.childNodes.length; k++) {
// Establish the Key, we are going to fill in the formatted value of the already found attribute
var sKey = foVal.childNodes[k].firstChild.text;
jDE.attributes[sKey].formattedValue = foVal.childNodes[k].childNodes[1].text;
}
break;
}
}
results[i] = jDE;
}
//return entities
if (callback != null) callback(results);
else return results;
}
function jsDynamicEntity(gID, sLogicalName) {
this.guid = gID;
this.logicalName = sLogicalName;
this.attributes = new Object();
}
function jsCrmValue(sType, sValue) {
this.type = sType;
this.value = sValue;
}
function jsEntityReference(gID, sLogicalName, sName) {
this.guid = gID;
this.logicalName = sLogicalName;
this.name = sName;
this.type = "EntityReference";
}
function jsOptionSetValue(iValue, sFormattedValue) {
this.value = iValue;
this.formattedValue = sFormattedValue;
this.type = "OptionSetValue";
}
/////////////Fetch XML
function getFieldValue(prmEntityType, prmEntityId, prmFieldName) {
var fieldValue = null;
var resultXml = RetrieveEntityById(prmEntityType, prmEntityId, prmFieldName);
if (resultXml != null && resultXml.selectSingleNode('//q1:' + prmFieldName) != null)
fieldValue = resultXml.selectSingleNode('//q1:' + prmFieldName).nodeTypedValue;
return fieldValue;
}
function getOptionSetLabel(prmEntityType, prmValue, prmFieldName) {
var label = null;
var str_ETC;
switch (prmEntityType) {
case "gits_licensing_of_artist_band": str_ETC = "10026"; break;
default: break;
}
var sFetch = "<fetch mapping='logical'>" +
"<entity name='stringmap'>" +
"<attribute name='value' />" +
"<filter type='and'>" +
"<condition attribute='objecttypecode' operator='eq' value='" + str_ETC + "'/>" +
"<condition attribute='attributename' operator='eq' value='" + prmFieldName + "'/>" +
"<condition attribute='langid' operator='eq' value='1033'/>" +
"<condition attribute='attributevalue' operator='eq' value='" + prmValue + "'/>" +
"</filter>" +
"</entity>" +
"</fetch>";
_oService = new FetchUtil(_sOrgName, _sServerUrl);
var res = _oService.Fetch(sFetch);
if (res.length > 0)
label = res[0].attributes["value"].value;
return label;
}
function PapulateTemBlockCityGovernate()
{
//debugger;
var att_block = Xrm.Page.getAttribute("gits_block");
var att_City , att_Governate , att_CityName , att_LookupType;
var resultXml = RetrieveEntityById("gits_block", att_block.getValue()[0].id, "gits_city,gits_governate");
if (resultXml != null && resultXml.selectSingleNode('//q1:gits_city') != null)
{
att_City = resultXml.selectSingleNode('//q1:gits_city').nodeTypedValue;
//att_CityName = resultXml.selectSingleNode('//q1:gits_city').attributes[0].text;
att_CityName = resultXml.selectSingleNode('//q1:gits_city').getAttribute("name");
att_LookupType = resultXml.selectSingleNode('//q1:gits_city').getAttribute("type");
// alert(att_LookupType);
// Xrm.Page.getAttribute("gits_address_city").setValue(null);
var cityData = new Array();
cityData[0] = new Object();
cityData[0].id = att_City;
cityData[0].name = att_CityName;
cityData[0].entityType = att_LookupType;
Xrm.Page.getAttribute("gits_city").setValue(cityData);
// Xrm.Page.getAttribute("gits_address_city").setSubmitMode("always");
}
if (resultXml != null && resultXml.selectSingleNode('//q1:gits_governate') != null)
{
att_Governate = resultXml.selectSingleNode('//q1:gits_governate').nodeTypedValue;
Xrm.Page.getAttribute("gits_governate").setValue(att_Governate);
}
}
function ConfirmSave()
{
if (confirm(" Are you sure you want to save?"))
{
return true;
}
// Cancel the save operation.
event.returnValue = false;
return false;
}
function SetPropertyValues()
{
//debugger;
var att_property , att_entityName , propertyType;
var tab_1 = Xrm.Page.ui.tabs.get("tab_1");
var sec_property_detail = tab_1.sections.get("PropertyDetail");
if ( Xrm.Page.getAttribute("gits_property_type")!= null )
propertyType = Xrm.Page.getAttribute("gits_property_type").getValue();
else if (Xrm.Page.getAttribute("gits_application_type") != null )
propertyType = Xrm.Page.getAttribute("gits_application_type").getValue();
else
propertyType = Xrm.Page.getAttribute("gits_propertytype").getValue();
Xrm.Page.getAttribute("gits_propertynameenglish").setValue( null );
Xrm.Page.getAttribute("gits_propertynamearabic").setValue( null );
if (propertyType!=null)
{
if (propertyType == 449930000)
{
att_property = Xrm.Page.getAttribute("gits_hotel");
if ( att_property == null )
att_property = Xrm.Page.getAttribute("gits_hotelid");
att_entityName="gits_hotel";
}
else if (propertyType == 449930001)
{
att_property = Xrm.Page.getAttribute("gits_apartment");
att_entityName="gits_apartment";
if ( att_property == null )
att_property = Xrm.Page.getAttribute("gits_apartmentid");
}
else if (propertyType == 449930002)
{
att_property = Xrm.Page.getAttribute("gits_restaurant");
att_entityName="gits_restaurant";
if ( att_property == null )
att_property = Xrm.Page.getAttribute("gits_restaurantid");
}
else if (propertyType == 449930003)
{
if ( Xrm.Page.getAttribute("gits_othersid") != null )
att_property = Xrm.Page.getAttribute("gits_othersid");
else
att_property = Xrm.Page.getAttribute("gits_officeagency");
att_entityName="gits_property_others";
}
if ( att_property!=null && att_property.getValue() != null )
{
var att_name_arabic , att_name_english;
var resultXml = RetrieveEntityById(att_entityName, att_property.getValue()[0].id, "gits_arabic_name,gits_english_name");
if (resultXml != null && resultXml.selectSingleNode('//q1:gits_arabic_name') != null)
{
att_name_arabic = resultXml.selectSingleNode('//q1:gits_arabic_name').nodeTypedValue;
Xrm.Page.getAttribute("gits_propertynamearabic").setValue(att_name_arabic);
}
if (resultXml != null && resultXml.selectSingleNode('//q1:gits_english_name') != null)
{
att_name_english = resultXml.selectSingleNode('//q1:gits_english_name').nodeTypedValue;
Xrm.Page.getAttribute("gits_propertynameenglish").setValue(att_name_english);
}
sec_property_detail.setVisible(true);
}
else
{
Xrm.Page.getAttribute("gits_propertynamearabic").setValue( null );
Xrm.Page.getAttribute("gits_propertynameenglish").setValue( null );
}
}
}
function ValidateLicensingDepartmentUser()
{
debugger;
var userID = Xrm.Page.context.getUserId();
var _Filter = "/SystemUserSet?$select=BusinessUnitId&$filter=SystemUserId eq (guid'" + userID + "')";
var _ResultSet = SendRequest(_Filter);
if (_ResultSet != null && _ResultSet.results.length == 1)
{
if (_ResultSet.results[0].BusinessUnitId.Name != null && _ResultSet.results[0].BusinessUnitId.Id =="7b325BC15B-5B9F-E211-975C-0050568E2E4F")
{
return true;
}
else
return false;
}
}
function SendRequest(_Filter) {
try {
//configure end point
var _ResultSet = null;
var _EndPoint = Xrm.Page.context.getServerUrl() + "/xrmservices/2011/organizationdata.svc";
var _XMLHttpRequest = new XMLHttpRequest();
_XMLHttpRequest.open("GET", _EndPoint + "/" + _Filter, false);
_XMLHttpRequest.setRequestHeader("Accept", "application/json");
_XMLHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
var _Result = _XMLHttpRequest.send();
if (_XMLHttpRequest.readyState == 4 && _XMLHttpRequest.status == 200) {
_ResultSet = this.parent.JSON.parse(_XMLHttpRequest.responseText).d;
}
return _ResultSet;
}
catch (Err) {
alert(Err);
return;
}
}
That function is called onchange of a field and it gives the error: Unable to get value of the property 'length': object is null or undefined
I think the error because of the browser comaptiblity with the javascript code. but I don't know what to edit
Thanks,