cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate V
Advocate V

Clicking a Button with a patch statement sometimes returns the following message: "This Items has already been created on the Server"

Sometimes when Clicking a Button with a patch statement sometimes the following message is returned: "This Items has already been created on the Server"

What is this error message, and what does this exactly mean ?

 

The Button then has a small red "X" in the upper left hand corner in the developer mode.

9 REPLIES 9
Highlighted
Advocate II
Advocate II

That means there is an error or a save conflict. Can you post the code on the button, erasing any sensitive information.

Highlighted

Yes, here is our code:

 

UpdateIf(ServiceCalls,Service_Call_ID=ServiceCall_Gallery.Selected.Service_Call_ID,
{ASMApprove: If(IsBlank(ASMApprove) || ASMApprove=0 , 1,0)
}
);

If(
   IsEmpty(
           Filter('[dbo].[PA_Approvals]',
           Service_Call_ID=ServiceCall_Gallery.Selected.Service_Call_ID && PRM_Asset_Id=0 && ApproveType="ASM Approve")
   )=false,
   Patch('[dbo].[PA_Approvals]', First(Filter('[dbo].[PA_Approvals]', Service_Call_ID=ServiceCall_Gallery.Selected.Service_Call_ID && PRM_Asset_Id = 0 && ApproveType="ASM Approve")),
        {

            Timestamp: If(

                         First(Filter('[dbo].[vwFTM_Service_Call_All_iPad]', Service_Call_ID=ServiceCall_Gallery.Selected.Service_Call_ID)).ASMApprove =0
                         ||
                         IsBlank(First(Filter('[dbo].[vwFTM_Service_Call_All_iPad]', Service_Call_ID=ServiceCall_Gallery.Selected.Service_Call_ID)).ASMApprove) =true,  

                         Now(),
                         DateTimeValue("1900-01-01")),
                        
            UserId: vUserOnly
        }
    ),

 Patch('[dbo].[PA_Approvals]',Defaults('[dbo].[PA_Approvals]'),
    {
            Service_Call_ID: ServiceCall_Gallery.Selected.Service_Call_ID,
            EquipmentId: "No Equip Id",
            PRM_Asset_Id: 0,
            ApproveType: "ASM Approve",
            Timestamp: Now(),
            UserId: vUserOnly
    }

));
Refresh('[dbo].[PA_Approvals]');
Refresh('[dbo].[vwFTM_Service_Call_All_iPad]');
ClearCollect(ServiceCalls,'[dbo].[vwFTM_Service_Call_All_iPad]');
Reset(ServiceCall_Gallery)

 

 

 

Please let me know if there is anything incorrect.

 

What is painful is having to do the Refreshes, ClearCollects and Reset Gallery at the end, to show the must up to date data.

 

Clearly this shouldn't be required ?

Highlighted

I don't think the refreshes are necessary. I have encounter the same errors when refreshing a SQL DB connection. If it is a gallery or a Tabledata, it should refresh automatically.

At least that is my understanding

Highlighted

I believe the refreshes are required.

The If Clauses will not work without refreshes.

Correct me, if mistaken or if code can be rewritten to not require it.

Highlighted

I am not 100% sure about the refreshes.

I noticed the refreshes happen after the If statements.

So again what is the purpose of refreshing the databases? Is it so a gallery or form refreshes?

 

Almost time to go home, tomorrow I will test a gallery and see if it updates automatically afer inserting a record. I know for sure that a DataTable updates automatically because I just finished an App that uses a datatable connected to a SQL.

 

Highlighted

Here is an update to our code, and we are still getting the "...Already Been Created on the Server" error message:

 

If(
   IsEmpty(Filter('[dbo].[PA_Approvals]',
           Service_Call_ID=vSC && PRM_Asset_Id=vPRM_Asset_Id && ApproveType="Equip Tasks"))=true,
           Patch('[dbo].[PA_Approvals]', Defaults('[dbo].[PA_Approvals]'),
           {
            Service_Call_ID: vSC,
            PRM_Asset_Id: vPRM_Asset_Id,
            ApproveType: "Equip Tasks",
            EquipmentId: vEquipment_ID,
            Timestamp: Now(),
            UserId: vUserOnly
           }
           ),
           Patch('[dbo].[PA_Approvals]', First(Filter('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = vPRM_Asset_Id && ApproveType="Equip Tasks")),
           {
            Timestamp: If(
                         Year(First(Filter('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = vPRM_Asset_Id && ApproveType="Equip Tasks")).Timestamp)<=1901 ,
                         Now(),
                         DateTimeValue("1900-01-01")),
            UserId: vUserOnly
            }
    ));

Refresh('[dbo].[PA_Approvals]');
Refresh('[dbo].[vwFTM_Equipment_Logging_All_iPad]')

 

Highlighted

HI @vsslasd ,

Based on the formula that you provided, I could not find any syntax error with it.

On your side, please consider take a try to modify your formula as below:

If(
   IsBlank(LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id=vPRM_Asset_Id && ApproveType="Equip Tasks")),
   Patch(
'[dbo].[PA_Approvals]',
Defaults('[dbo].[PA_Approvals]'), { Service_Call_ID: vSC, PRM_Asset_Id: vPRM_Asset_Id, ApproveType: "Equip Tasks", EquipmentId: vEquipment_ID, Timestamp: Now(), UserId: vUserOnly } ), Patch(
'[dbo].[PA_Approvals]',
LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = vPRM_Asset_Id && ApproveType="Equip Tasks"), { Timestamp: If( Year(LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = vPRM_Asset_Id && ApproveType="Equip Tasks").Timestamp) <= 1901 , Now(), DateTimeValue("1900-01-01")), UserId: vUserOnly } )
);
Refresh('[dbo].[PA_Approvals]');
Refresh('[dbo].[vwFTM_Equipment_Logging_All_iPad]')

 

In addition, please check if you have enabled Unique property for the Service_Call_ID,  PRM_Asset_IdApproveTypEquipmentIdTimestamp or UserId column in your SQL Table. If yes, please make sure that the value that provided for the corresponding Unique column is unique (not repeated) when you patch new record into your SQL Table data source.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted

Hello, I have modified the code as follows:

 

If(
   IsBlank(LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id=0 && ApproveType="ASM")),
           Patch('[dbo].[PA_Approvals]', Defaults('[dbo].[PA_Approvals]'),
           {
            Service_Call_ID: vSC,
            PRM_Asset_Id: 0,
            ApproveType: "ASM",
            EquipmentId: "No Equip Id",
            Timestamp: Now(),
            UserId: vUserOnly
           }
           ),
           Patch('[dbo].[PA_Approvals]', LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = 0 && ApproveType="ASM"),
           {
            Timestamp: If(
                         Year(LookUp('[dbo].[PA_Approvals]', Service_Call_ID=vSC && PRM_Asset_Id = 0 && ApproveType="ASM").Timestamp)<=1901 ,
                         Now(),
                         DateTimeValue("1900-01-01")),
            UserId: vUserOnly
            }
           )
    );
Refresh('[dbo].[PA_Approvals]');
Refresh('[dbo].[vwFTM_Service_Call_All_iPad]')

 

I'm still getting the error message.

 

The SQL Azure table structure is as follows:

 

/****** Object: Table [dbo].[PA_Approvals] Script Date: 3/15/2019 9:20:47 AM ******/

SET ANSI_NULLS ON

 

GO

SET QUOTED_IDENTIFIER ON

 

GO

CREATE TABLE [dbo].[PA_Approvals](

[RowId] [int] IDENTITY(1,1) NOT NULL,

[Service_Call_ID] [varchar](17) NOT NULL,

[EquipmentId] [varchar](31) NOT NULL,

[PRM_Asset_Id] [int] NOT NULL,

[ApproveType] [varchar](5) NOT NULL,

[Timestamp] [datetime] NULL,

[UserId] [varchar](15) NULL,

[RecommendationRowId] [int] NULL,

CONSTRAINT [PK_PA_Approvals] PRIMARY KEY CLUSTERED

 

(

[Service_Call_ID] ASC,

[PRM_Asset_Id] ASC,

[ApproveType] ASC

)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]

) ON [PRIMARY]

 

GO

ALTER TABLE [dbo].[PA_Approvals] ADD CONSTRAINT [DF_PA_Approvals] DEFAULT (getdate()) FOR [Timestamp]

 

GO

ALTER TABLE [dbo].[PA_Approvals] ADD CONSTRAINT [DF_PA_Approvals_RecommendationRowId] DEFAULT ((0)) FOR [RecommendationRowId]

 

GO

 

 

Based upon the code, the Primary Key should be fine as it is, as opposed to all of the columns in the table as suggested.

Can you please guide us? This should not be problematic.

Thank you.

 

Highlighted

Kris, I am testing this code and it doesn't work.

It's on an OnSelect Button property.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (8,888)