Thank you Andrew.
Sorry my response took so long, we had a major release and I was involved in that.
I'm not an experienced Dynamics user and I'm sure I could use your response to solve my problem, but sadly for now I'm not exactly sure how to implement it.
Had to go with the script:
function disable_owner_change() {
setTimeout(function () { // Had to set timeout because form was loading slow and can't get the OwinerID
var roleId = '2a0f75b3-8f50-ea11-a883-000d6a8bfcc8'; // Agent RoleID
var currentUserRoles = Xrm.Utility.getGlobalContext().userSettings.securityRoles; // Get current user security roles
var userRoleId = currentUserRoles[0]; // Getting the first role (and the only role in my case)
if (userRoleId == roleId && currentUserRoles.length == 1) { // Checking if current user is Agent and it's the only role
var OwnerIDorig = Xrm.Page.getAttribute("ownerid").getValue()[0].id; // Check the current Opportunity owner role
var OwnerID = OwnerIDorig.toString();
if (OwnerID == "{78F45BC3-4E75-EA54-A823-000D3A30F547}" || OwnerID == "{65564BC7-E593-EA12-A871-000D3A76E885}") { // Check if current Opportunity owner is Admin (in dev or prod env)
Xrm.Page.getControl("header_ownerid").setDisabled(false);
}
else {
Xrm.Page.getControl("header_ownerid").setDisabled(true);
}
}
}, 3000);
}
I'm pretty sure it's not the elegant script version but had no time to dig it up.
Please fill free to modify it or suggest an edit, will be glad to use it.
Thanks.