Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

Run script on a View

(0) ShareShare
ReportReport
Posted on by 18

I'm trying to setup a script for use in a Model-driven App which will run when Views are loaded within that App. For example, say the user visits Accounts and sees a View listing All Active Accounts.

 

I am aware that it's possible to load PCF controls into Views, however before I start doing that I'm looking for a more generic way of having a script load on every page load within the App. The script will be able to determine what it should do depending on what kind of page it is running on. This is a much better solution for me than customizing each and every View within the App with a PCF control. However, I haven't been able to find anything on running scripts at the App level, ie. something that loads and runs on every page within the App.

 

Is there any way of doing this, or will I have to resort to inserting a PCF control on every applicable View?

 

TIA, Ben

 

 

  • Verified answer
    benPWP Profile Picture
    18 on at
    Re: Run script on a View

    Final post to pull everything together. The goal was to get my custom script loaded 'globally' (at least on every Entity View in Dynamics 365). 

     

    The solution was to create a new custom button on the Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab ribbon, which makes that button display on all Entity Homepage ribbons.

    See https://community.dynamics.com/forums/thread/details/?threadid=e93bf785-e33b-43b3-bd31-030fabb18036 for reference.

     

    However, since the custom javascript file is only loaded when the button is pressed, and I needed it loaded when the page loaded in order to run my custom script on every Entity homepage without user interaction, it was necessary to make a Ribbon Enable Rule for the custom button, and to direct the Enable Rule to a function in my custom javascript file. The function simply returns true, since I always want the button to be enabled. This forces the custom javascript to be loaded on page load, since the Ribbon calls the custom script to see if the button should be enabled or not. 

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Run script on a View

    @robinsonjra Enable Rules/Custom Type

  • rrodrigueza Profile Picture
    3 on at
    Re: Run script on a View

    @benArrayx What type of rule are you referring to?

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Run script on a View

    Don't forget to mark an answer and set like 😉

  • benPWP Profile Picture
    18 on at
    Re: Run script on a View

    So, in order to make the custom load on the page without any user interaction, I setup an enable rule for my new button which calls a function in my custom code, therefore the custom code file is loaded without any need for user interaction! Simply return false to the enable rule and the button is also hidden 🙂

     

    Thanks @a33ik for pointing me in the right direction!

  • benPWP Profile Picture
    18 on at
    Re: Run script on a View

    OK, so I have added a button to the Mscrm.HomepageGrid.{!EntityLogicalName}.MainTab ribbon, which does make that button display on all Entity Homepage ribbons as required. The button calls a javascript function in my custom code, however, my custom code file is not loaded until the button is pressed. Therefore, this does not work for me as a 'global' script since I need the custom code file to be loaded without having to press a button. The custom code file already runs the code I need run when it is loaded, all I need is for it to be loaded with the page without any specific user interaction required...

     

    Any other ideas?

  • benPWP Profile Picture
    18 on at
    Re: Run script on a View

    Hi there, thanks for that, but the article you linked to describes how to put a button on every Form in the app, what I want is to run some code on every View in the app. I get that maybe I could do that from the ribbon, but not from the Form ribbon! However this post seems to suggest that there is an "Application" Ribbon, I'll try that! https://community.dynamics.com/forums/thread/details/?threadid=e93bf785-e33b-43b3-bd31-030fabb18036

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Run script on a View

    Hello,

    If the goal to add a button to every entity and make kinda "global" here is the way to go - https://www.itaintboring.com/dynamics-crm/application-ribbon-in-dynamics-or-how-can-we-add-a-button-to-all-entity-forms/

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 55 Most Valuable Professional

#2
mmbr1606 Profile Picture

mmbr1606 44 Super User 2025 Season 1

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 31 Super User 2025 Season 1

Overall leaderboard