Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

Javascript - checking a lookup value for null failing

$
0
0

Hi,

I am writing a odata request in a script which is retrieving the values that I need correctly. Problem is when the retrieved value is null, I am checking if the value is null or not before proceeding further but it ignores the if condition and enters the loop even though the value is null.

Country is a lookup field. Can someone please guide me through this? Thanks.

Here is my script:

function fillAppName()
{
debugger;
var  formType= Xrm.Page.ui.getFormType();
if(formType==1)
{
var userId=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 userApplication = retrievedUser.new_Application;
        var userCountry=retrievedUser.new_country;
        //return userFullName;

if(userApplication!=null){
var appValue=new Array();
appValue[0]=new Object();
appValue[0].id=userApplication.Id;
appValue[0].name=userApplication.Name;
appValue[0].entityType=userApplication.LogicalName;

Xrm.Page.getAttribute("new_application").setValue(appValue);
}
if(userCountry!=null && userApplication.Name!='xxxx')//it enters the loop here even if userCountry is null
		{
		var countryValue = new Array();
		countryValue[0] = new Object();
		countryValue[0].id = userCountry.Id;
		countryValue[0].name = userCountry.Name;
		countryValue[0].entityType = userCountry.LogicalName;

		Xrm.Page.getAttribute("new_country").setValue(countryValue);
}

    }
    else {
        return "error";
    }
}
}

Thanks for any help!


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images