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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

Custom Timer Control

(5) ShareShare
ReportReport
Posted on by 274
Hi all,
 
Is there a way to have an On-Demand timer control inserted into a D365 form? This wouldn't be linked to any SLA, it would just run, pause and stop based on a few toggle fields and count up, not down.
 
I tried using the OTB one but it seems to require triggers that I'm not wanting to link it to.
 
Any help would be hugely appreciated with internet points :D
 
Cheers!
 
Sam
I have the same question (0)
  • Suggested answer
    Daivat Vartak (v-9davar) Profile Picture
    7,835 Super User 2025 Season 2 on at
    Hello Sam,
     

    Yes, absolutely! You can definitely create an on-demand timer control within a Dynamics 365 form that isn't tied to SLAs and operates based on your custom toggle fields. The out-of-the-box (OTB) Timer control is indeed designed with SLA tracking in mind and has specific trigger requirements.

    To achieve your requirement, you'll need to leverage the Power Apps Component Framework (PCF) to build a custom control. Here's a breakdown of the approach and key considerations:

    Core Approach: Build a Custom PCF Control

    PCF allows developers to create custom UI components that can be seamlessly integrated into model-driven apps (like Dynamics 365). This is the ideal way to create a timer with the exact behavior you need.

    Key Elements of Your Custom PCF Control:

    1. UI Rendering: You'll need to use HTML, CSS, and JavaScript within your PCF control to render the timer display (e.g., displaying hours, minutes, seconds).

    2. Start/Pause/Stop Logic:

      • You'll bind your PCF control to one or more Boolean (Two Options) fields on your D365 form. These fields will act as your "toggle fields."

      • Your JavaScript code will monitor the changes in these toggle fields.

      • Based on the state of the toggle fields:

        • Start: When the "Start" toggle field is set to "Yes" (or your defined value), initiate the timer interval using setInterval().

        • Pause: When the "Pause" toggle field is set to "Yes", clear the interval using clearInterval() to stop the timer at its current value.

        • Stop/Reset: When the "Stop" toggle field is set to "Yes", clear the interval and reset the timer's displayed value to zero.

        •  
         

    3. Timer Value Storage:

      • You'll need a way to store the elapsed time. You can bind your PCF control to a Whole Number (Integer) or Text (Single Line of Text) field on your D365 form to persist the timer's value.

      • In your setInterval() function, you'll increment the timer value and update both the displayed UI and the bound D365 field.


      •  

    4.  

    Steps to Build the PCF Control (High-Level):

    1. Set up your PCF development environment: This involves installing Node.js, the Power Platform CLI, and a suitable code editor (like Visual Studio Code).

    2. Create a new PCF project: Use the Power Platform CLI command:

      pac pcf init --namespace YourNamespace --name OnDemandTimerControl --template field


    3. Implement the control's logic in index.ts:

      • Define input properties: These will correspond to your toggle fields (Start, Pause, Stop) and the field to store the timer value.

      • Implement the init method: This is called when the control is loaded. You'll initialize your UI elements here.

      • Implement the updateView method: This is called whenever the bound data changes (i.e., when your toggle fields are updated). This is where you'll implement the start, pause, and stop logic using setInterval() and clearInterval(). You'll also update the displayed timer value.

      • Implement the getOutputs method: This is called when data needs to be passed back to Dynamics 365 (e.g., when the timer value changes). You'll update the bound timer value field here.

      • Implement the destroy method: Clean up any resources.

      •  

    4. Define the control's manifest in ControlManifest.Input.xml:

      • Declare the input properties that will be bound to your toggle fields and the timer value field.

      • Define the output property for the timer value.

      •  

    5. Build and package the PCF control: Use the Power Platform CLI commands:

      npm install
      npm run build
      pac pcf push --publisher-prefix yourprefix


    6. Import the PCF control solution into your Dynamics 365 environment.

    7. Add the PCF control to your D365 form:

       

      • Open the form in the form editor.

      • Select the field where you want to display the timer.

      • Go to the Controls tab in the field properties.

      • Click Add Control... and select your custom "OnDemandTimerControl."

      • Configure the bindings between the control's input properties and your toggle fields and the timer value field.

      • Ensure the control is enabled for Web, Phone, and Tablet as needed.

      • Click Save and Publish your customizations.


      •  

    8.  

    Example (Conceptual JavaScript in updateView):

    private intervalId: NodeJS.Timeout | null = null;
    private startTime: number = 0;
    private elapsedTime: number = 0;
    public updateView(context: ComponentFramework.Context<IInputs>): void {
      const shouldStart = context.parameters.startToggle.raw === true;
      const shouldPause = context.parameters.pauseToggle.raw === true;
      const shouldStop = context.parameters.stopToggle.raw === true;
      const timerValueControl = context.parameters.timerValue;
      if (shouldStart && !this.intervalId) {
        this.startTime = Date.now() - this.elapsedTime;
        this.intervalId = setInterval(() => {
          this.elapsedTime = Date.now() - this.startTime;
          this.updateTimerDisplay(this.elapsedTime);
          // Update the bound D365 field
          timerValueControl.raw = Math.floor(this.elapsedTime / 1000); // Example: store in seconds
          context.outputs.timerValue = timerValueControl;
          context.notifyOutputChanged();
        }, 1000); // Update every second
        context.parameters.startToggle.raw = false; // Reset the toggle
      } else if (shouldPause && this.intervalId) {
        clearInterval(this.intervalId);
        this.intervalId = null;
        context.parameters.pauseToggle.raw = false; // Reset the toggle
      } else if (shouldStop) {
        clearInterval(this.intervalId);
        this.intervalId = null;
        this.elapsedTime = 0;
        this.updateTimerDisplay(0);
        timerValueControl.raw = 0;
        context.outputs.timerValue = timerValueControl;
        context.notifyOutputChanged();
        context.parameters.stopToggle.raw = false; // Reset the toggle
      }
      // Update the UI with the current elapsed time
      this.updateTimerDisplay(this.elapsedTime);
    }
    private updateTimerDisplay(milliseconds: number): void {
      const seconds = Math.floor((milliseconds / 1000) % 60);
      const minutes = Math.floor((milliseconds / (1000 * 60)) % 60);
      const hours = Math.floor(milliseconds / (1000 * 60 * 60));
      const display = `${this.pad(hours)}:${this.pad(minutes)}:${this.pad(seconds)}`;
      // Update the HTML element displaying the timer
      this.timerContainer.innerText = display;
    }
    private pad(num: number): string {
      return num < 10 ? '0' + num : num.toString();
    }

     

    Internet Points Earned! 🌟🌟🌟

    Building a PCF control will give you the exact on-demand timer functionality you need without the constraints of the OTB Timer control's SLA dependency. It requires development effort, but it's the most flexible and robust solution for this scenario.

     
    If my answer was helpful, please click Like, and if it solved your problem, please mark it as verified to help other community members find more. If you have further questions, please feel free to contact me.
     
    My response was crafted with AI assistance and tailored to provide detailed and actionable guidance for your Microsoft Dynamics 365 query.
     
    Regards,
    Daivat Vartak
  • Suggested answer
    Saif Ali Sabri Profile Picture
    2,351 Super User 2025 Season 2 on at
    You can implement an on-demand timer in a Dynamics 365 form using a custom PCF control (Power Apps Component Framework). Here's a concise solution:
    Approach: Custom PCF Timer Control
    Requirements:
    • Use a PCF control to create a timer that:
      • Starts, pauses, stops manually
      • Counts up (not linked to SLAs or OTB timer logic)
      • Reads/writes to toggle fields to control state
    Steps:
    1. Create a new PCF control using the Power Apps CLI:
    bash  CopyEdit
    pac pcf init --namespace YourNamespace --name CustomTimerControl --template field
    1. Build timer logic in index.ts:
      • Use setInterval() for time counting
      • Read from bound fields (e.g., timerStatus) to start/pause/stop
      • Display elapsed time on the control UI
    2. Bind fields in D365:
      • timerStatus (OptionSet or Boolean): start, pause, stop
      • elapsedTime (Duration/Whole Number): to store time
    3. Deploy the control:
      • Build & import the solution
      • Add the control to your desired form field
    4. Optional: Use a Web Resource to simulate the timer if a PCF is not viable, but PCF is preferred for better integration and UX.

    This gives full flexibility without relying on SLA logic. Let me know if you want a sample PCF repo or help with the code.
  • Suggested answer
    Holly Huffman Profile Picture
    6,538 Super User 2025 Season 2 on at
    Good morning, afternoon, or evening depending on your location!
     
    I understand your need for a timer that operates independently of SLAs and can be controlled via toggle fields.
    Unfortunately, the out-of-the-box (OTB) timer control in Dynamics 365 is designed to work with SLA triggers, which limits its flexibility for your use case. However, here are some alternative approaches to achieve your desired functionality:
    1. Custom PCF Timer Control
    • You can create a Power Apps Component Framework (PCF) control to build a custom timer.
    • This control can be embedded into your form and configured to start, pause, and stop based on toggle fields.
    • The timer can be set to count up and display elapsed time dynamically.
    2. JavaScript-Based Timer
    • Use JavaScript to implement a timer directly on the form.
    • The script can monitor the toggle fields and update a custom field or control on the form to display the elapsed time.
    • This approach is lightweight and doesn’t require PCF development.
    3. Canvas App Integration
    • If you’re open to using a Canvas App, you can design a timer within the app and embed it into your model-driven form.
    • Canvas Apps provide flexibility for creating interactive controls like timers.
    4. Third-Party Solutions
    • Explore third-party solutions or components available in the Microsoft AppSource marketplace.
    • Some pre-built controls might meet your requirements without the need for custom development.
     
    Hope this helps some!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans