Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Script Error - Lead Entity

Posted on by 110

Hi All, 

I'm running into an issue with a script error that keeps popping up when the FormOnLoad and OnSave.

We do have JS for RemoveOptionSet in the form, but it has been there for awhile and the issues recently started happening.

I copied the lead entity to test removing the JS from the entity, and it was still happening with it completely removed.  I even removed associated fields for it.

I'm not sure what the main cause is.  Can anyone point me in the right direction?

1016.FormProperties.jpg

Code:

function RemoveOptionIndexFromPicklist(attributeName, value, index)
{
var attrName = attributeName;
if (index != undefined && index != null)
{
attrName = attrName + index;
index += 1;
}
else
{
index = 1;
}
var attrControl = Xrm.Page.getControl(attrName);
if (attrControl != null)
{
try
{
attrControl.removeOption(value);
removeOptionSetValue(attributeName, value, index);
}
catch (e)
{}
}
}

function RemoveOptions()
{
RemoveOptionIndexFromPicklist("leadsourcecode", 1);
RemoveOptionIndexFromPicklist("leadsourcecode", 2);
RemoveOptionIndexFromPicklist("leadsourcecode", 3);
RemoveOptionIndexFromPicklist("leadsourcecode", 4);
RemoveOptionIndexFromPicklist("leadsourcecode", 7);
RemoveOptionIndexFromPicklist("leadsourcecode", 8);
RemoveOptionIndexFromPicklist("leadsourcecode", 9);
RemoveOptionIndexFromPicklist("leadsourcecode", 10);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000001);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000002);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000003);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000004);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000005);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000006);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000007);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000008);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000009);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000010);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000011);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000012);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000014);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000018);
RemoveOptionIndexFromPicklist("leadsourcecode", 100000019);
RemoveOptionIndexFromPicklist("new_leadlevel", 100000004);
RemoveOptionIndexFromPicklist("new_leadlevel", 100000005);
RemoveOptionIndexFromPicklist("new_leadlevel", 100000007);
RemoveOptionIndexFromPicklist("new_leadlevel", 100000008);
RemoveOptionIndexFromPicklist("new_leadlevel", 100000009);
}

*This post is locked for comments

  • MS Helper Profile Picture
    MS Helper 110 on at
    RE: Script Error - Lead Entity

    Hi Jdalske, I would probably start a new thread. This one is pretty old at this point.

    If it is a very similar issue to what I stated above, you will want to export the entire lead form entity, and just that. Then, you will want to open it up in the Code Writer app and comment out the areas where the script is showing an error. I used Alex's suggestion above to find the error in the debugging window of Chrome by pressing F12 and then accessing the form.  This showed exactly the lines that were causing issues. Once in code writer, I commented them out (//) and re-imported them. It solved the issue. I've had no issues since I posted this in 2017.

  • jdalske Profile Picture
    jdalske 536 on at
    RE: Script Error - Lead Entity

    I am having a similar issue on the Account Entity form.  Am I supposed to start a new question or post to this thread?

  • Verified answer
    MS Helper Profile Picture
    MS Helper 110 on at
    RE: Script Error - Lead Entity

    Hi All, thanks for the suggestions you provided.

    I took the advice of Ravi and Alex to fix the issue.

    While I was debugging in Chrome, I could see that it kept referencing a Mscrm.Lead Web Resource that wasn't in CRM for both .formOnLoad and .form_OnSave

    We ended up exporting just the lead form entity, opening up customizations.xml in code view, and commenting out both of these lines.  We imported it back into the system and the script error went away.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Script Error - Lead Entity

    Are the formOnLoad and form_OnSave functions within your script file? If so, can you share them?

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Script Error - Lead Entity

    Hi,

    maybe it is just a stupid remark, but your "RemoveOptionIndexFromPicklist" definition says that it needs 3 parameters. And every calls in "RemoveOptions()" only have 2 parameters.

    Could it be your problem?

  • MS Helper Profile Picture
    MS Helper 110 on at
    RE: Script Error - Lead Entity

    Sorry, I don't know what happened to the original image, here are the error messages.

    SaveOnErrorScript.jpg

    SaveOnErrorScript.jpg

    Are you asking for the functions under the event handler in form properties different from up above?

    There is nothing specific I can find to OnSave in the lead entity.

  • MS Helper Profile Picture
    MS Helper 110 on at
    RE: Script Error - Lead Entity

    These were the only errors that popped up in debugging.

    Errors.jpg

    I probably need to trim some fat on the code, it was done in March sometime and hasn't been touched since.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Script Error - Lead Entity

    Can you show the onLoad and onSave functions as well?

    Can you show an actual screenshot and/or text of the error message?

    Thanks.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Script Error - Lead Entity

    Also, try debugging (in chrome, use F12.. then refresh the screen.. see where the error happens)

    BTW, I'm wondering what's that removeOptionSetValue - there is a call to that function, but I don't see the function in the code

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Script Error - Lead Entity

    Hi,

    The error message is complaining about something 'formOnload' which seems like a custom javascript method however the script and screenshot you have shared, you do not have anything with that name.

    I would suggest to check this on a different browser or incognito mode.

    If the issue still happens, then export the solution with only the lead entity and check the customization.xml to see what all events are registered there. This could a corrupted form scenario.

    Hope this helps.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans