Hi experts,
I have a bunch of True/False fields in the account record:
I also have replicated the same fields in the case record:
I have a account lookup field in case record called customerid. Now when I load the case form, I would like to auto populate the values of these field from account to case.
I tried field mapping, but that only works on create of record and doesn't update when values change. So, I used the following script to auto populate but it only works, if the fields are marked as True and doesn't work when they are False.
function getValues() { var contactId; var res; var lookupItem = Xrm.Page.getAttribute("customerid").getValue(); if (lookupItem != null) { contactId = lookupItem[0].id; // Added new line res = contactId.replace("{", "").replace("}", ""); } else { return; } var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+res+")?$select=new_redflag,new_dns", false); 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 redflag = result["new_redflag"]; var dns = result["new_dns"]; if(redflag) { Xrm.Page.getAttribute("new_redflag").setValue(redflag); } if(dns) { Xrm.Page.getAttribute("new_dns").setValue(dns); } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }
How can I change my code for this to work?
Thanks,
Jon
*This post is locked for comments