Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

ReferenceError: SetOrgType_RO is not defined

Posted on by Microsoft Employee

I set this script to fire OnLoad in the Form Properties.  When it fires it is throwing the error: ReferenceError: SetOrgType_RO is not defined.

FormPropertiesOnLoad.PNG

Does anyone see the problem in the Code below?

function SetOrgType_RO(){
    setTimeout(function(){
        var currentUserRoles = Xrm.Page.context.getUserRoles();
        for (var i = 0; i < currentUserRoles.length; i++) {
            var userRoleId = currentUserRoles[i];
            var userRoleName = GetRoleName(userRoleId);
            If (userRoleName == "OrgTypeUpdate") {
                // Xrm.Page.ui.controls.get("new_organizationtype").setDisabled(false);
                alert("Ok, Lannie");
                return true;
            }
        }
        return false;
        
        function GetRoleName(userRoleId) {
            var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name";
            var odataSelect = GetServerUrl() + selectQuery;
            alert(odataSelect);
            var roleName = null;
            $.ajax({
                type: "GET",
                async: false,
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataSelect,
                beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
                success: function (data, textStatus, XmlHttpRequest) {
                    var result = data.d;
                    if (!!result) {
                        roleName = result.results[0].Name;
                    }
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) {
                    alert('OData Select Failed: ' + odataSelect);
                }
            });
            return roleName;
        }
    }, 2000);
}

*This post is locked for comments

  • a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: ReferenceError: SetOrgType_RO is not defined

    I believe so. Why do you ask?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ReferenceError: SetOrgType_RO is not defined

    Andrii,  Did you get credit for your response of 26 Sep 2017 8:21 AM?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ReferenceError: SetOrgType_RO is not defined

    Thank you once again...

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: ReferenceError: SetOrgType_RO is not defined

    I'm old enough to understand that miracles do not exist ;) There is an explanation why your customization doesn't work properly.

    Try to change line

    If (userRoleName == "OrgTypeUpdate") {

    to line

    if (userRoleName == "OrgTypeUpdate") {

    if has to be lowercased.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: ReferenceError: SetOrgType_RO is not defined

    Thank you for the response Andrew, but the result is the same.  I believe it has something to do with the Sandbox.

    I have another script running in Production that, has the same content, failed in the Sandbox. 

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: ReferenceError: SetOrgType_RO is not defined

    Hello,

    It looks like function you reference is not available for execution for some reason. Can you try publish webresource, clean cache and reload the page?

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans