Dear All,
I am new in the Community and JavaScript and have a question regarding a problem I am facing. I am sure the solution is quiet simple but I cant find it I hope you can help me out.
I have created a Customization within Dynamics CRM 2015 and I am trying to get the following accomplished:
I have a JavaScript which is Locking specific fields if the CurrentUserID is NOT equal to the CreatedByID of a record.
I also only want the script to be active when the Form is an Update Form and not on Create.
The script is working fine when I open an existing record. But when I create a new record I get an Error message:
Field: window
Event: onload
Error: undefined
The script is set to execute OnLoad of the Form.
Here is the code:
function enableCreatedbyEditl() {
var isCreateForm = (Xrm.Page.ui.getFormType() == 1);
var isUpdateForm = (Xrm.Page.ui.getFormType() == 2);
if (isUpdateForm === true) {
var currUserId = Xrm.Page.context.getUserId();
var currCreatedBy = Xrm.Page.getAttribute("createdby").getValue();
var currCreatedById = currCreatedBy[0].id;
if (currUserId == currCreatedById)
{
Xrm.Page.getAttribute("ownerid").controls.get(0).setDisabled(false);
}
else
{
Xrm.Page.getAttribute("ownerid").controls.get(0).setDisabled(true);
}
}
else if (isCreateFormForm === true) {
noaction();
}
}
Can anyone let me know how I can get rid of the Error and what my mistake is within the code?
As I said the Script is working the way I need it I just want to get rid of the Error.
Thanks A Lot
Jake