RE: Set Field Based Upon Logged in User
Hi Justin,
You could also use JS code to do this.
We just need to get the current login user first and set his Business unit to the field, here is the sample code.
//Get Buniness Unit according to the current login user and set it as default value to BUnit field
function setBusinessUnit(executionContext) {
var formContext = executionContext.getFormContext();
var useridOrg = Xrm.Page.context.getUserId();
var userid = useridOrg.substring(1, useridOrg.length - 1);
Xrm.WebApi.retrieveRecord("systemusers", userid, "?$select=_businessunitid_value").then(
function success(result) {
var _businessunitid_value = result._businessunitid_value;
var _businessunitid_value_formatted = result["_businessunitid_value@OData.Community.Display.V1.FormattedValue"];
var field = formContext.getAttribute("new_businessunit");
var lookupValue = new Array();
lookupValue[0] = new Object();
lookupValue[0].id = _businessunitid_value; // GUID of the lookup id
lookupValue[0].name = _businessunitid_value_formatted; // Name of the lookup
lookupValue[0].entityType = "businessunit"; //Entity Type of the lookup entity
field.setValue(lookupValue);
},
function (error) {
alert(error.message);
}
);
}
Please add this js to webresource and add the "setBusinessUnit" function to Onload event in Account form.
And here is the result, when I opening Account form, the "Business Unit" field will be set value of the current user's Business Unit.
Hope it helps.
Best Regards,
Leo