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 / Trying to check if ID ...
Power Apps
Answered

Trying to check if ID is already in Database and notify user if it is, With, Multiple IF, Context Variables, Patch.

(0) ShareShare
ReportReport
Posted on by 174

Hi,

 

I have an app which a user inputs some text into a text input (Called TEXT_INPUT_OFSAMPLEID.Text) and then uses a buttons OnSubmit function.

 

I need the buttons OnSubmit function to do a few things,

 

1) Checks if a SampleID is already in one of two databases (SQLDataTable and TempData) and if it isnt then it patches, if it is Notify and Reset the TEXT_INPUT_OFSAMPLEID.Text to blank

2) If a context variable (varDoublePatchData) is equal to true, then patch it twice (see code), this context variable is controlled by a check box, if varDoublePatchData is equal to false then patch once.

 

The following code is what i have been working on for a few days, using the following it does work if i have a SampleID that is already in the system and it doesnt patch,

 

But now i have two problems one problem is it also notifies me if the TEXT_INPUT_OFSAMPLEID.Text is blank (every so often its supposed to be blank) and the second problem is it also notifies me if the SampleID is correct, it allows me to patch in both circumstances but i need it to not show that error.

 

I cant for the life of me work out where the error is? ive tried labeling it and dumbing it down for myself but i cant understand it.

 

Could someone look at my code and help me out?

 

Also CBSampleID is a checkbox i use to make the SampleID appear blank,

 

 

With(
 {
 withSAMIDSQL: LookUp(
 SQLDataTable,
 SampleID = TEXT_INPUT_OFSAMPLEID.Text
 ).SampleID,
 withSAMIDSharepoint: LookUp(
 TempData,
 SampleID = TEXT_INPUT_OFSAMPLEID.Text
 ).SampleID
 },
	
 If(
 IsBlank(withSAMIDSharepoint) && IsBlank(withSAMIDSQL)	&& 
 If(varDoublePatchData=true, 
	Patch(TempData,
		Defaults(TempData),
 {
 PID:DisplayPIDLabel.Text,
 SampleID: If(CBSampleID.Value = true, "", TEXT_INPUT_OFSAMPLEID.Text),
		TEXTCOLUMN: "1"
 
 }
	);
	Patch(TempData,
		Defaults(TempData),
 {
 PPID:DisplayPIDLabel.Text,
 SampleID: If(CBSampleID.Value = true, "", TEXT_INPUT_OFSAMPLEID.Text),
		TEXTCOLUMN: "2"
 }
	);UpdateContext({varMode : "TEMP"});
, 
	Patch(TempData,
		Defaults(TempData),
 {
 PID:DisplayPIDLabel.Text,
 SampleID: If(CBSampleID.Value = true, "", TEXT_INPUT_OFSAMPLEID),
		TEXTCOLUMN: "1"
 }
	)
	;UpdateContext({varMode : "Continue"})
 ,
 Notify("THERE IS ALREADY AN SAMPLE WITH THAT EXACT SAMPLEID, PLEASE CHECK SAMPLEID AND TRY AGAIN");
 TEXT_INPUT_OFSAMPLEID = "";
 
);
)

 

 

 

 

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,969 Most Valuable Professional on at

    Hi @SomeoneAwesome ,

    I tried to put some logic to this as below - the code should be valid (although Notepad does not assist here) - make sure the logic is

    With(
     {
     withBlank: 
     IsBlank(
     LookUp(
     SQLDataTable,
     SampleID = TEXT_INPUT_OFSAMPLEID.Text
     ).SampleID
     ) && 
     IsBlank( 
     LookUp(
     TempData,
     SampleID = TEXT_INPUT_OFSAMPLEID.Text
     ).SampleID
     )
     },
     If(
     withBlank,
     Patch(
     TempData,
     Defaults(TempData),
     {
     PID: DisplayPIDLabel.Text,
     SampleID: 
     If(
     CBSampleID.Value, 
     "", 
     TEXT_INPUT_OFSAMPLEID.Text
     ),
     TEXTCOLUMN: "1"
     }
     );
     If(
     varDoublePatchData, 
     Patch(
     TempData,
     Defaults(TempData),
     {
     PPID: DisplayPIDLabel.Text,
     SampleID: 
     If(
     CBSampleID.Value, 
     "", 
     TEXT_INPUT_OFSAMPLEID.Text
     ),
     TEXTCOLUMN: "2"
     }
     )
     );
     UpdateContext(
     {
     varMode: 
     If(
     varDoublePatchData,
     "TEMP",
     "Continue"
     )
     }
     ), 
     Notify(
     "THERE IS ALREADY AN SAMPLE WITH THAT EXACT SAMPLEID, PLEASE CHECK SAMPLEID AND TRY AGAIN"
     );
     TEXT_INPUT_OFSAMPLEID = "";
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • SomeoneAwesome Profile Picture
    174 on at

    Perfect Warren, thanks a million.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 139

Last 30 days Overall leaderboard