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

setValue not working

$
0
0
I have an on load javascript function that is called when a new record is created. It retrieve the territory for the User and I want to populate that territory to the form. I'm able to successfully retrieve the territory, using XHR, but when I try to call setValue using that territory it doesn't work... Code is below:
function weeklyReport_OnLoad() {
    //only on create
    if (Xrm.Page.ui.getFormType() == 1) {
        var id = Xrm.Page.context.getUserId();
        id = id.replace("{", "").replace("}", "");
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/SystemUserSet(guid'" + id + "')?$select=am_DWTerritory", true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.onreadystatechange = function() {
            if (this.readyState === 4) {
                this.onreadystatechange = null;
                if (this.status === 200) {
                    var result = JSON.parse(this.responseText).d;
                    var am_DWTerritory = result.am_DWTerritory;
                    // alert("Setting DW Territory");
                    // console.log(am_DWTerritory);
                    // alert(am_DWTerritory.Name);
                    Xrm.Page.getAttribute("dwterritory").setValue(am_DWTerritory);
                } else {
                    alert(this.statusText);
                }
            }
        };
        req.send();
    }
}

Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>