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
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
Try to debug the script by pressing F12.
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Community Member 2
UllrSki 2
SC-08081331-0 1