Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Creating a namspace defined JS library template

Posted on by 270

Hello,

I am trying to have a template for JS file. I have a lot of functions I want to run on load, change, and Save.  I have created the below I am getting error message "executionContext Undefined at hideShow". Thank you for the help.

// JavaScript source code
if (typeof DEMO == "undefined") {
    DEMO = { __namespace: true };
}


DEMO.Case = (function () {
    var $self = {};
   
        var formContext = executionContext.getFormContext();
  
   
    //debugger;

    //onLoad
    $self.onLoad = function () {
       // var formContext = executionContext.getFormContext();
        hideShow(executionContext);
    }
    //onSave
    $self.onSave = function () {
        //LoadFormContext(formContext);
     

    }

    //OnChange Events
    $self.OnChange = function () {
         //LoadFormContext(formContext);
         hideShow(executionContext);
    }


    function hideShow() {
      var formContext = executionContext.getFormContext();
        if (formContext.getAttribute("fieldName").getValue() == "") {
            formContext.ui.tabs.get("tabName").setVisible(false);
        }
        else
            formContext.ui.tabs.get("tabName").setVisible(true);
    }


    
    return $self;



})();


*This post is locked for comments

  • MituCRMing Profile Picture
    MituCRMing 270 on at
    RE: Creating a namspace defined JS library template

    Yes, I have tried that as well, also read the article

    / JavaScript source code
    if (typeof DEMO == "undefined") {
        DEMO = { __namespace: true };
    }
    
    
    DEMO.Case = (function () {
        var $self = {};
       
            var formContext = executionContext.getFormContext();
      
       
        //debugger;
    
        //onLoad
        $self.onLoad = function () {
           // var formContext = executionContext.getFormContext();
            hideShow(executionContext);
        }
        //onSave
        $self.onSave = function () {
            //LoadFormContext(formContext);
         
    
        }
    
        //OnChange Events
        $self.OnChange = function () {
             //LoadFormContext(formContext);
             hideShow(executionContext);
        }
    
    
        function hideShow(executionContext) {
          var formContext = executionContext.getFormContext();
            if (formContext.getAttribute("fieldName").getValue() == "") {
                formContext.ui.tabs.get("tabName").setVisible(false);
            }
            else
                formContext.ui.tabs.get("tabName").setVisible(true);
        }
    
    
        
        return $self;
    
    
    
    })();


  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Creating a namspace defined JS library template

    Hi,

    You need to pass execution context as parameter to your method, I will suggest you to check read this :community.dynamics.com/.../executioncontext-hits-the-big-time

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans