When creating a new opportunity, there is a another field titled /Branch/ which I need to auto populate from the branch from the current user.
I believe this is possible using JS, but I cant work out the code required.
function getBranch(executionContext) {
var formContext = executionContext.getFormContext();
//Get current user
var userSettings = Xrm.Utility.getGlobalContext().userSettings;
var currentuserid = userSettings.userId;
//Retrieve the user to get branch value
Xrm.WebApi.retrieveRecord("systemuser", currentuserid, "?$select=_cr5a3_branch_value").then(
function success(result) {
console.log(result);
// Columns
var systemuserid = result["systemuserid"]; // Guid
var cr5a3_branch = result["_cr5a3_branch_value"]; // Lookup
var cr5a3_branch_formatted = result["_cr5a3_branch_value@OData.Community.Display.V1.FormattedValue"];
var cr5a3_branch_lookuplogicalname = result["_cr5a3_branch_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
//Set Branch in opportunity | cr5a3_branch_lookuplogicalname is logic name of the Brach in the opportunity
formContext.getAttribute("cr5a3_branch_lookuplogicalname").setValue([{ id: cr5a3_branch, name: cr5a3_branch_formatted, entityType: cr5a3_branch_lookuplogicalname }]);
},
function (error) {
console.log(error.message);
}
);
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156