Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

Error handling in econnect stored procedure

(0) ShareShare
ReportReport
Posted on by 18

Hi,

We are using econnect stored procedure to create purchase invoice in Dynamics GP.

We have done customization in 'taPMDistributionPost' stored procedure. We want to add error handling in stored procedure.

I have tried to use Try Catch in stored procedure, but the error does not catch into the catch block.

Do I need to use different way for error handling?

Thank you in advance for your assistance!

Categories:
  • Suggested answer
    Derek Albaugh Profile Picture
    on at
    RE: Error handling in econnect stored procedure

    In the eConnectProgrammersGuide.pdf, it states the following which may help get you started:

    To use the eConnect error handling process, you add output parameters that

    can hold an ErrorState value and an ErrString message. ErrorState specifies

    whether an error occurred and ErrString includes error codes and other

    information.

    To add a stored procedure to your database server, refer to the SQL Server help

    documentation for information about installing SQL stored procedures.

    The following SQL example shows a stored procedure for the

    <eConnectCustomProcedure> XML node. Notice that the

    eConnectCustomProcedure name matches the name of the node.

    Also notice how

    the input parameter named I_vCUSTNMBR maps to the CUSTNMBR element of

    the node. Finally, notice that the procedure includes output parameters named

    O_iErrorState and oErrString that enable the procedure to return error information.

    /* Begin_Procs eConnectCustomProcedure */

    if exists (select * from dbo.sysobjects where id =

    Object_id('dbo.eConnectCustomProcedure') and type = 'P')

    begin

    drop proc dbo.eConnectCustomProcedure

    end

    go

    create procedure dbo.eConnectCustomProcedure

    @I_vCUSTNMBR char(15), /* Customer Number - only required field */

    @O_iErrorState int output, /* Return value: 0 = No Errors, Any Errors > 0 */

    @oErrString varchar(255) output /* Return Error Code List */

    as

    declare

    @CUSTBLNC int,

    @O_oErrorState int,

    @iError int,

    @iStatus smallint,@iAddCodeErrState int

    /*********************** Initialize locals ******************************/

    select

    @O_iErrorState = 0,

    @oErrString = '',

    @iStatus = 0,

    @iAddCodeErrState = 0

    /***************** Custom Procedure edit check validation ***************/

    /*If the @I_vCUSTNMBR variable is '' then we need to add the error code */

    /*35010 to the @oErrString output variable.*/

    /*The method that eConnect uses to append all error string is the */

    /*taUpdateString procedure.*/

    /*Error codes can be appended to the @oErrString variable: for example you */

    /*could append a 33 44 55 66 to the @oErrString variable */

    /*After the error codes have been appended to the @oErrString variable. */

    /***********************************************************************/

    if ( @I_vCUSTNMBR = '' )

    begin

    select @O_iErrorState = 35010 /* Customer number is empty */

    exec @iStatus = taUpdateString

    @O_iErrorState,

    @oErrString,

    @oErrString output,

    @iAddCodeErrState output

    end

    /* Do some custom business logic */

    select @CUSTBLNC = CUSTBLNC

    from RM00103 (nolock)

    where CUSTNMBR = @I_vCUSTNMBR

    /* End custom business logic */

    return (@O_iErrorState)

    go

    grant execute on dbo.eConnectCustomProcedure to DYNGRP

    go

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,277 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,019 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans