Hi Nilanka,
I actually have a working code for you i did this earlier :
function retrieveBranchValue:()
{
var userid = Xrm.Page.getAttribute("ownerid").getValue();
var newid = userid[0].id.slice(1, -1);
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/systemusers(" + newid + ")?$select=_branch_value", true); //get branch from user
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 userbranch = result._branch_value; //get the id of the brnach
var userbranchformatted = result["_branch_value@OData.Community.Display.V1.FormattedValue"]; //get the formatted name of the branch
if (userbrnach != null) {
var value = new Array();
value[0] = new Object();
value[0].id = userbranch;
value[0].name = userbranchformatted;
value[0].entityType = "branch";
Xrm.Page.getAttribute("branch").setValue(value); //set the lookup
}
else
alert("Your user profile is missing branch information; please add and try again!")
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
kindly change the schema name of the field and entity of branch.
call the function on onload of your account form or as per your needs.
mark my suggestion as verified if helpful.