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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Run script on a View
Power Apps
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

 

 

I have the same question (0)
  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    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/

  • benPWP Profile Picture
    18 on at

    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

  • benPWP Profile Picture
    18 on at

    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

    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!

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

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

  • rrodrigueza Profile Picture
    3 on at

    @benArrayx What type of rule are you referring to?

  • a33ik Profile Picture
    3,306 Most Valuable Professional on at

    @robinsonjra Enable Rules/Custom Type

  • Verified answer
    benPWP Profile Picture
    18 on at

    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. 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard