connector call from business object returning multiple values including state

  • Klaus79
    Participant
      5 years, 7 months ago #17992

      How can I call a connector which returns lastInsertedId or success state (e.g.: {
      “message”: “Duplicate entry ‘1-1-DE’ for key ‘PRIMARY'”,
      “success”: false
      }

      I know how I’ll get inserted id.

      Currently my connector call Looks like this:

      var insertedID = Simplifier.Connector.DataLoad.saveDate_NotationFromSAP({
      CustID: input.CustID,
      SystemID: input.SystemID,
      params: date_notation_dataset
      }).generatedID;

      But how do I get message state from SQL db if insertion runs into error?

      I thought that a try-catch-block solves the problem but it never throws an exception which I can process further in catch-block.

      Chris Bouveret
      Keymaster
        Has successfully completed the online course Introduction
        Has successfully completed the online course Intermediate (200)
        Has successfully completed the online course Advanced (300)
        Has successfully completed the online course Basics (100)
        Has successfully completed the online course Advanced (320)
        Has successfully completed the Intermediate Certification
        Has successfully completed the Advanced Certification
      5 years, 6 months ago #18230
      Up
      0
      Down
      ::

      Hi Klaus,

      when using the SQL connector please use the “transaction” mode. It will return the last inserted ID for most databases.

      Hope that helps

      Klaus79
      Participant
        5 years, 5 months ago #18518
        Up
        0
        Down
        ::

        But what about  if insert statement runs into problems and returns following error message (in connector test dialog):

        “message”: “Duplicate entry ‘1-1-DE’ for key ‘PRIMARY’”,
        “success”: false

         

        I’ve tried to get it with a try-catch-block in business object but that did not work.

        Also output parameters in connector isn’t working for that database errors.

         

        How do I get access to the error message so I can react in bussiness object on it?

        Chris Bouveret
        Keymaster
          Has successfully completed the online course Introduction
          Has successfully completed the online course Intermediate (200)
          Has successfully completed the online course Advanced (300)
          Has successfully completed the online course Basics (100)
          Has successfully completed the online course Advanced (320)
          Has successfully completed the Intermediate Certification
          Has successfully completed the Advanced Certification
        5 years, 5 months ago #18522
        Up
        0
        Down
        ::

        Hi Klaus,

        please do the following within your BusinessObject to catch errors:

        if(yourConnectorResult) {
        if(yourConnectorResult.length) {
        // do stuff
        }
        } else {
        throw new Error("Your Error Message");
        }

        Hope that helps

        Klaus79
        Participant
          5 years, 5 months ago #18523
          Up
          0
          Down
          ::

          Hi Chris,

          that’s a possiblity if  I have an output parameter and if I want to know if there is a result.

          But how do I get the origingal sql error message (e.g. ‘timeout error’, ‘duplicate entry for’, ‘Can’t connect to database’, etc.) from the red rectangle.

          I

          Klaus79
          Participant
            5 years, 5 months ago #18597
            Up
            0
            Down
            ::

            No suggestion?

            I’m stucking because my array of data won’t be processed further if there is e.g. a ‘duplicate entry xyz for primary key’ error.

             

             

            Mathieu Roll
            Keymaster
              Has successfully completed the online course Introduction
              Has successfully completed the online course Intermediate (200)
              Has successfully completed the online course Advanced (300)
              Has successfully completed the online course Basics (100)
            5 years, 4 months ago #18697
            Up
            0
            Down
            ::

            Hello Klaus,

            you already mentioned the solution a try catch block.

            No idea what you did wrong but for me it works.

            Like you can see my sql insert will always throw an error because i have a duplicate.

            In my Business Object im using a try catch block to catch the error and create a simplifier log entry.

          Viewing 7 posts - 1 through 7 (of 7 total)

          You must be logged in to reply to this topic.