Hello,
I have custom have called WorkOrder and there is lookup Business Unit on it which contains all the BU list with parent and Child BU . When a record to associated to Particular BU on selecting Lookup and when trying to creating associated child record on Taskform entity i need to validate whether logged user is comes under selected BU on WorkOrder. If we select parent BU on WorkOrder record and logged user is Child BU user then how to validate using javascript .
It works fine using following code when comparing on 2 BU ids but need to check if child BU user with Parent record BU. Please suggest.
function retrieveWOBU() {
//read lookup value
debugger;
if (Xrm.Page.getAttribute("new_workorder").getValue() != null && Xrm.Page.getAttribute("new_workorder").getValue()[0].id != null) {
var workorderid = Xrm.Page.getAttribute("new_workorder").getValue()[0].id;
//pass entity, fields, we can use expand to get related entity fields
Xrm.WebApi.retrieveRecord("new_workorder", workorderid, "$select=new_name&$expand=new_businessunit($select=businessunitid,name)").then(
function success(result) {
if (result != null) {
//set text field
//set lookup field
if (result.new_businessunit != null) {
var UserBUID = GetUserBU()
if (result.new_businessunit.businessunitid != UserBUID) {
setFormNotification("Logged User doesn't belogs to WO BU", "ERROR", "1");
}
}
}
},
function (error) {
alert(error.message);
}
);
}
}
function GetUserBU() {
var UserId = Xrm.Page.context.getUserId();
Cols = ["businessunitid"];
var Retrieved = XrmServiceToolkit.Soap.Retrieve("systemuser", UserId, Cols);
var UnitObj = Retrieved.attributes["businessunitid"];
var businessunitid = UnitObj.id
return (businessunitid);
}