cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stavrinio85
Frequent Visitor

Issues when changing a number in database through powerapps which calls a trigger procedure

Untitled.png

USE [BOC_DEMO]
GO
/****** Object: Trigger [dbo].[After_Update_ToClose] Script Date: 12/5/2018 9:00:48 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE TRIGGER [dbo].[After_Update_ToClose] ON [dbo].[NumBranches]
AFTER UPDATE AS

DECLARE @num INT;
BEGIN


SET @num = ( select NumOfBranchesToClose from NumBranches);


CREATE TABLE [dbo].[tmp_toClose1](
[Branch] [nvarchar](255) NOT NULL,
[Lat] [float] NULL,
[Lon] [float] NULL,
[Address] [nvarchar](255) NULL,
[Town] [nvarchar](255) NULL,
[District] [nvarchar](255) NULL,
[NumofServices] [float] NULL,
[Profit] [float] NULL,
[Action] [nvarchar](255) NULL,
[CloseFlag] [nvarchar](200) NOT NULL,
PRIMARY KEY CLUSTERED
(
[Branch] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[tmp_toClose2](
[Branch] [nvarchar](255) NOT NULL,
[Lat] [float] NULL,
[Lon] [float] NULL,
[Address] [nvarchar](255) NULL,
[Town] [nvarchar](255) NULL,
[District] [nvarchar](255) NULL,
[NumofServices] [float] NULL,
[Profit] [float] NULL,
[Action] [nvarchar](255) NULL,
[CloseFlag] [nvarchar](200) NOT NULL,
PRIMARY KEY CLUSTERED
(
[Branch] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

--Select @num= NumOfBranchesToClose from NumBranches;
-- Insert statements for trigger here
--DELETE FROM NumBranches

DELETE FROM [dbo].[Close_Branches]
OUTPUT deleted.* INTO tmp_toClose1

--Output Delete.* into tmp_toClose

Insert into Close_Branches
output inserted.* into tmp_toClose2
SELECT top (@num) *
from Branches b
order by [Profit]

Drop Table tmp_toCLose1
Drop Table tmp_toClose2
END

 

From the powerapps i update the numbranches table which has one property as a pk.

as soon as this is updated it triggers the above code to update another table.

 

i get this error message.

Anyone has experience?

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @stavrinio85

I understand how much of a problem this is.

The general workaround is to create a SQL Stored Procedure that carries out your data operation. In your example, this Stored Procedure would update [dbo].[NumBranches] and update the records in [dbo].[Close_Branches] using your business logic. You would then call this Stored Procedure via Flow, rather than update the table directly in PowerApps.

View solution in original post

4 REPLIES 4
timl
Super User
Super User

Hi @stavrinio85

Unfortunately, PowerApps doesn't support tables with Triggers.

The 'known issues and limitations' section of the SQL Connector help page provides a little bit more detail.

https://docs.microsoft.com/en-us/connectors/sql/#known-issues-and-limitations

stavrinio85
Frequent Visitor

So there is no way to make changes in the datasets in sql db by changing a single table and then triggering events to make the rest of the changes?
That seems unlikely not just a limitation but rather an issue.
What is the workaround with the flow you mentioned? How does that work?
I am way into the powerapp solution right now for me to drop the whole powerbi_powerapp thing.
Need to find a solution

Hi @stavrinio85

I understand how much of a problem this is.

The general workaround is to create a SQL Stored Procedure that carries out your data operation. In your example, this Stored Procedure would update [dbo].[NumBranches] and update the records in [dbo].[Close_Branches] using your business logic. You would then call this Stored Procedure via Flow, rather than update the table directly in PowerApps.

Anonymous
Not applicable

Thank you for your help with this post and the suggested workaround @timl

 

@Anonymous

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Users online (3,292)