Hi all !
I have a problem with getting the value from systemuser entity on save event. I am sharing my code below so maybe you can correct.
It says "Bad Request" when i click on save.
function autoFillSubject() { debugger; var FormType = Xrm.Page.ui.getFormType(); if ( FormType != "1" || FormType == null ) { return; } var userid = Xrm.Page.context.getUserId(); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/systemusers("+userid+")?$select=_territoryid_value", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function() { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); var _territoryid_value = result["_territoryid_value"]; var _territoryid_value_formatted = result["_territoryid_value@OData.Community.Display.V1.FormattedValue"]; var _territoryid_value_lookuplogicalname = result["_territoryid_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; var regarding = Xrm.Page.data.entity.attributes.get("regardingobjectid"); var regardingVal = regarding.getValue(); regardingVal = regardingVal[0].name; var date = Xrm.Page.data.entity.attributes.get("scheduledstart"); var dateVal = date.getValue(); var year = dateVal.getFullYear()+""; var month = (dateVal.getMonth()+1)+""; var day = dateVal.getDate()+""; var dateFormat = day + "/" + month + "/" + year; var subject = Xrm.Page.data.entity.attributes.get("subject"); subject.setValue(regardingVal + "-" + _territoryid_value_formatted + "-" + dateFormat); } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
*This post is locked for comments