Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Error in patching the records

(1) ShareShare
ReportReport
Posted on by 67

Hello guys , I am trying to pacth a record after a value is changed on a gallery  my value_id in sql table is ident and yes it's primary key  and I am trying to patch the new values as new rows

 

first: when i dont give it an value_id and says iw was not found 

 second : when I give a value_id it says it is auto generated 

 any help? 

Categories:
  • Abdulazizhalawa Profile Picture
    Abdulazizhalawa 67 on at
    Re: Error in patching the records

    thnaks the the above one solved my problem 

  • Verified answer
    EddieE Profile Picture
    EddieE 4,641 on at
    Re: Error in patching the records

    @Abdulazizhalawa 

    I cannot see any issues with your code. Sometimes after you run the code then get that Network error, your button / icon that holds the code will display a Red 'X' icon in the Editor. If you click on it, usually you will see where the error is coming from in your code. Maybe try this and see what it shows.

     

    Also, to use a code window that I explained above you select it from the icons above your reply window, ie

    EddieE_0-1686018985145.png

    Then copy your code into the window, ie

    Set(prodctIDSelected,SKUsDropDowns.Selected.product_id);
    If(
    	!IsBlank(CurrentValueInput.Text),
    	If(
    		(LookUp(clStandardValues, ThisItem.parameter_id = parameter_id)).standard_value <> CurrentValueInput.Text,
    		Set(LastValueID1,Max(clParameterValues,value_id));
    
    		Patch(clParameterValues, Defaults(clParameterValues),
    				{
    
    					parameter_id: 		LookUp( clParameterValues, parameter_id = ThisItem.parameter_id && product_id= prodctIDSelected).parameter_id,
    					last_run_value: 	LookUp(	
    											clParameterValues,
    											parameter_id = ThisItem.parameter_id &&	product_id = prodctIDSelected && 
    											value_id = Max(	Filter(	clParameterValues, parameter_id = ThisItem.parameter_id, product_id = prodctIDSelected), value_id)
    										).current_value,
    					current_value: 		15,
    					Reasons: 			LookUp(	clParameterValues, parameter_id = ThisItem.parameter_id&& product_id= prodctIDSelected).Reasons,
    					user_id: 			LookUp(	clParameterValues, parameter_id = ThisItem.parameter_id && product_id= prodctIDSelected).user_id,
    					submit_date:		Now(),
    					product_id:			prodctIDSelected
    				}
    		)
    		
    // I added these brackets below
    	)
    )

     

     

     

  • Abdulazizhalawa Profile Picture
    Abdulazizhalawa 67 on at
    Re: Error in patching the records

    </>

    Set(prodctIDSelected,SKUsDropDowns.Selected.product_id);
    If(
    !IsBlank(CurrentValueInput.Text),
    If(
    (LookUp(
    clStandardValues,
    ThisItem.parameter_id = parameter_id
    )).standard_value <> CurrentValueInput.Text,
    Set(LastValueID1,Max(clParameterValues,value_id));

    Patch(
    clParameterValues,
    Defaults(clParameterValues),
    {

    parameter_id: LookUp(
    clParameterValues,
    parameter_id = ThisItem.parameter_id && product_id= prodctIDSelected
    ).parameter_id,

    last_run_value:LookUp(
    clParameterValues,
    parameter_id = ThisItem.parameter_id&&
    product_id = prodctIDSelected&&
    value_id = Max(
    Filter(
    clParameterValues,
    parameter_id = ThisItem.parameter_id,
    product_id = prodctIDSelected
    ),
    value_id
    )
    ).current_value,
    current_value: 15,
    Reasons: LookUp(
    clParameterValues,
    parameter_id = ThisItem.parameter_id&& product_id= prodctIDSelected
    ).Reasons,
    user_id: LookUp(
    clParameterValues,
    parameter_id = ThisItem.parameter_id && product_id= prodctIDSelected
    ).user_id,
    submit_date:Now(),
    product_id:prodctIDSelected
    });</>

    what I am trying to do is if the current_value has changed i will collect what I need to collect then patch it to dat base as new record or row 

  • EddieE Profile Picture
    EddieE 4,641 on at
    Re: Error in patching the records

    @Abdulazizhalawa 

    You are mixing up Creating a New Record and Editing an existing one.

     

    The Default() function is used to Create a new record - you are trying to Edit an existing one so there is no need for this in your code.

    Swap

    Defaults( ... )
    with

    LookUp( ... your LookUp function goes here ...) 

     

    If you get stuck, post your code into a code window (using </>) and I can help re-write it for you.

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,445

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,741

Leaderboard