web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

odata query with null results

(0) ShareShare
ReportReport
Posted on by 2,665
Hi,

I am writing an oData query which can result null values. If the result is a null value, I would like to show/hide some fields. But my script fails to do so. Someone please take a look at it and let me know what could be the reason.



function getUserCounty(userId) { debugger; var createdOn=Xrm.Page.getAttribute("createdon").getValue(); if(createdOn!=null) { return; } var serverUrl = Xrm.Page.context.getClientUrl(); var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc"; var userRequest = new XMLHttpRequest(); userRequest.open("GET", ODataPath + "/SystemUserSet(guid'" + userId + "')", 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 county = retrievedUser.new_county; return county; } else { return "error"; } } var owner = Xrm.Page.getAttribute("ownerid").getValue(); if(owner!=null) { var ownerId = owner[0].id; var county = getUserCounty(ownerId); if(county!=null)//county with null value passes this condition which it shouldn't { var countyValue = new Array(); countyValue[0] = new Object(); countyValue[0].id = county.Id; countyValue[0].name = county.Name; countyValue[0].entityType = county.LogicalName; Xrm.Page.getAttribute("new_county").setValue(countyValue); } else//it never shows this field for a null county { Xrm.Page.ui.controls.get("new_formField").setVisible(true); } }

Thanks.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ScottDurow Profile Picture
    21 on at

    Could it be that your getUserCounty function is returning 'error'? I suggest that you use IE's F12 Network trace to look at the REST call and also use F12's Javascript debugger n IE to find the value that is returned.

    See msdn.microsoft.com/.../gg130952(v=vs.85).aspx

    Hope this helps,

    Scott

  • meenoo Profile Picture
    7,316 on at

    Try to debug the script by pressing F12.

    Thanks.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans