web
You’re offline. This is a read only version of the page.
close
Skip to main content
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
    RE: odata query with null results

    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
    RE: odata query with null results

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans