Issue with PATCH function to a SQL database

  • Issue with PATCH function to a SQL database

    Posted by John Heck on November 8, 2022 at 3:45 pm
    • John Heck

      Member

      November 8, 2022 at 3:45 PM

      Using the Patch function to write data to a SQL table. When I create the patch function no matter what fields I use I get the error message

      The type of this argument ‘PartNumber’ does not match the expected type ‘Text’. Found type ‘Error’.
      The function ‘PATCH’ has some invalid arguments.

      PartNumber is a nvarchar(50) in both SQL tables, PartAttribute & PartAttributeTable. Both tables have a Primary Key set.

      Here is the code that I am working with.

      ClearCollect(
           colPAT,
            ShowColumns(
                      Filter(
                                PartAttribute, PartNumber = txtLEPartNo_1.Text && Revision = txtLERevision_1.Text
                             ),
                     “ID”, “PartID”, “PartNumber”, “Revision”, “SequenceNumber”, “Diamond”, “Attribute”, “LowerLimit”, “LLUnits”, “UpperLimit”, “ULUnits”
                    )
      );

      // this code needs to be fixed

      ForAll(
          colPAT,
              Patch(
                   PartAttributeTable,
                   Defaults(PartAttributeTable),
                   {
                           PartNumber: PartNumber      // this is the line that receives the error.  1st PartNumber is in the PartAttributeTable and the 2nd one is in the colPAT from above.
                    }
                ) 
      );

      At one time I had this working and I needed to add a couple of new fields to the PartAttributeTable.  After adding the additional fields I did remove the table from the PowerApps and brought it back in.  Everything on the screen works fine and there are no errors with any other area that uses fields from the PartAttributeTable.

      Thanks in advance for your assistance.

      ——————————
      John Heck
      ——————————

    • Koen Mathijs

      Member

      November 9, 2022 at 3:43 PM

      John,

      can you show us what exactly is in PartNumber after you do your ClearCollect routine?
      It’s not clear to me what this field should contain because you do some sort of filtering on it (PartNumber = txtLEPartNo_1.Text && Revision = txtLERevision_1.Text)

      From the error message I get that a Text field is required (as it should because you declared it as a “nvarchar”) but actually some sort of error message is captured (The type of this argument ‘PartNumber’ does not match the expected type ‘Text’. Found type ‘Error’.)

      It looks like you are trying to Patch an error message in a text field and that’s why the Patch command is giving you this error.

      I could be way off but at this moment this is my best guess. Try to look at the content of PartNumber before you patch it

      ——————————
      Koen Mathijs
      ——————————
      ——————————————-

    • John Heck

      Member

      November 11, 2022 at 4:31 PM

      Koen,

      Thanks for the reply.  txtLEPartNo_1.Text is a text field formatted like 7122-067S and the txtLERevision_1.Text is a single letter, ie A B C D E, etc.  Both of the entry fields are Text Input fields on the screen.  I seem to be only having issues in this one sport and one other i just found out.  The other slice of code is below where something similar is happening in that it knows whether or not the If statement is true or false though it doesn’t update the varRevisionEntered or the varLastRevision fields with the associated text values.

      If(IsEmpty(LookUp(Parts, PartNumber = txtLEPartNo_1.Text && Revision = txtLERevision_1.Text)),
          UpdateContext({varRevisionEntered: txtLERevision_1.Text});
          UpdateContext({varLastRevision: Last(
                LastN(
                            SortByColumns(Filter(Parts, PartNumber= txtLEPartNo_1.Text),
                            “Revision”, Ascending),1
                       )
                ).Revision
                 }),
              UpdateContext({varRevisionEntered: txtLERevision_1.Text});
              UpdateContext({varLastRevision: txtLERevision_1.Text});
      );

      Thanks for the help.

      ——————————
      John Heck
      ——————————
      ——————————————-

    John Heck replied 1 year, 6 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘Issue with PATCH function to a SQL database’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for people  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!