web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Java Script Error when creating a new Record

(0) ShareShare
ReportReport
Posted on by

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

*This post is locked for comments

I have the same question (0)
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    I would suggest to remove

    noaction();

    line

  • Community Member Profile Picture
    on at

    Thanks A lot. I tried this earlier but got an error as well. I just noticed I have a Typo in my script now it is working and the last bit looks like:

    else if (isCreateForm === true) {

    }

    }

    I had isCreateFormForm earlier

    Thanks & Regards

    Jake

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans