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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to refresh propert...
Power Apps
Unanswered

How to refresh property of code component

(0) ShareShare
ReportReport
Posted on by 8

Dear all,

        I have a custom code component, which can generate watermark for the image while user take phone using a camera control.

But there is a problem, a custom attribute is not automatically updated when taking photos,

cheng32_3-1686572872325.png

the formula configuration of the custom attribute is as follows

originalDataUrl

cheng32_0-1686571388505.png

Timestamp

cheng32_1-1686571449976.png

Then I want to Know how to refresh Time stamp while user take phone by Camera1 control

cheng32_2-1686572276230.png

Now, The control can get the latest picture from the camera, but the timestamp property cannot get the latest time.

My control code is as follows,

import { IInputs, IOutputs } from "./generated/ManifestTypes";

export class ImageWaterMark implements ComponentFramework.StandardControl<IInputs, IOutputs> {
 private _originalDataUrl: string; 
 private _resultDataUrl: string; // 
 private _waterMarkText: string; // 
 private _timeStampText: string; //
 private _notifyOutputChanged: () => void;
 private watermarkedImage: HTMLImageElement;
 private orginalImage: HTMLImageElement;
 private timeStampInput: HTMLInputElement; // 
 private _container: HTMLDivElement;
 private _context: ComponentFramework.Context<IInputs>;
 private _refreshData: EventListenerOrEventListenerObject;

 constructor() {

 }
 
 public watermarkImageWithText(originalImage: HTMLImageElement, watermarkText: string, timeStampText: string) {
 const canvas = document.createElement("canvas");
 const ctx = canvas.getContext("2d");
 const canvasWidth = originalImage.width;
 const canvasHeight = originalImage.height;
 canvas.width = canvasWidth;
 canvas.height = canvasHeight;
 if (ctx != null) {
 // initializing the canvas with the original image
 ctx.drawImage(originalImage, 0, 0, canvasWidth, canvasHeight);
 ctx.fillStyle = "black";
 ctx.textBaseline = "middle";
 ctx.textAlign = "right";
 ctx.font = "normal 10px arial";
 ctx.fillText(timeStampText, canvasWidth, canvasHeight - 10);
 ctx.fillText(watermarkText, canvasWidth, canvasHeight - 25);
 }
 return canvas.toDataURL();
 }
 
 public refreshData(evt: Event): void {
 console.log('refresh data invoked!');
 this._originalDataUrl = this.orginalImage.src as any as string;
 this._timeStampText = this.timeStampInput.value as any as string;

 if (this._waterMarkText != null && this._waterMarkText != '') {

 this._resultDataUrl = this.watermarkImageWithText(this.orginalImage, this._waterMarkText, this._timeStampText);
 
 this.watermarkedImage.src=this._resultDataUrl;
 
 this._notifyOutputChanged();
 }
 else {
 console.log('waterMarkText is empty!');

 } 
 }
 
 public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement): void {
 console.log(`init context.parameters.WaterMarkText:${context.parameters.WaterMarkText}`);
 this._context = context;
 this._waterMarkText = context.parameters.WaterMarkText.raw!;
 this._timeStampText = context.parameters.TimeStampText.raw!;
 this._notifyOutputChanged = notifyOutputChanged;
 this._refreshData = this.refreshData.bind(this);

 this._container = document.createElement("div");
 this.watermarkedImage = document.createElement("img");
 this.watermarkedImage.setAttribute("id", "watermarkedImage");
 this.orginalImage = document.createElement("img");
 this.orginalImage.setAttribute("id", "originalImage");
 this.orginalImage.style.visibility = "hidden"; 
 this.orginalImage.onload =this._refreshData;

 this.timeStampInput = document.createElement("input");
 this.timeStampInput.setAttribute("type", "text");
 this.timeStampInput.onchange = this._refreshData;
 this.timeStampInput.setAttribute("value", this._timeStampText); 
 
 this._container.appendChild(this.timeStampInput);
 this._container.appendChild(this.watermarkedImage);
 this._container.appendChild(this.orginalImage);
 container.appendChild(this._container);
 } 
 public updateView(context: ComponentFramework.Context<IInputs>): void {
 console.log('update view');
 this._waterMarkText = context.parameters.WaterMarkText.raw!;

 if (this._timeStampText != context.parameters.TimeStampText.raw!) {
 this._timeStampText = context.parameters.TimeStampText.raw!;
 this.timeStampInput.setAttribute("value", this._timeStampText);
 (this.timeStampInput as any).onchange();
 }

 if (this.orginalImage.src != context.parameters.OriginalData.raw!) {
 this.orginalImage.src=context.parameters.OriginalData.raw!;
 }
 this._context = context;
 }
 
 public getOutputs(): IOutputs {
 return {
 WatermarkedData: this._resultDataUrl,
 };
 }
 
 public destroy(): void {
 // Add code to cleanup control if necessary
 this.orginalImage.removeEventListener("load", this._refreshData);
 this.timeStampInput.removeEventListener("change", this._refreshData);
 }
}

 

Would appreciate it if it could be solved.

I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 549 Most Valuable Professional

#2
Kalathiya Profile Picture

Kalathiya 225 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 224

Last 30 days Overall leaderboard