Skip to main content

Creating a SalesPad Custom Procedure (SPCP) - Knowledgebase / SalesPad / Miscellaneous - Cavallo Technical Support

Creating a SalesPad Custom Procedure (SPCP)

Authors list
Overview

This document reviews the steps needed to create a SalesPad Custom Procedure (SPCP) in SQL Server Management Studio (SSMS). Custom procedures add functionality to SalesPad beyond what is provided in the standard stored procedures, and they can be tailored to provide customer specific features. Many of SalesPad's default procedures have built-in support for a custom procedure. For a list of procedures that have a code call to an SPCP, see the documentation here. Unlike SalesPad's default procedures, custom procedures do not get overwritten or refreshed when you run a database update.

Disclaimer: SalesPad is not responsible for the code in the SPCP or any issues that are a result of modified logic used in the SPCP. Testing any changes to stored procedures in a non-production database is highly recommended. If a support issue is found to be related to a customer- or partner-written SPCP, any time spent by SalesPad may be billable.

Creating a Custom Procedure

Some default procedures (see the list mentioned above) have a SQL call to a custom procedure. If a custom procedure does not exist for the chosen default procedure, the default procedure runs normally. If a custom procedure does exist, the code call in the default procedure will cause the custom procedure to execute in place of the default.

Using a Predefined Template

Some stored procedures have an included template meant for use as a template to create a custom procedure. In this documentation, we'll be starting with the template procedure sppSalesMonitor_Modified. Once created, certain sections of this template can be un-commented to add functionality that the default procedure does not have.


1. In SSMS, locate the stored procedure that you will be creating a custom procedure for.

xsyqpCsXJz00P7UbHFGoLk9YwW2J9834.png?access_token=snx3ts-kvyselaqld-6eae9466028e883d59896736724f5d4177c4e5d7

2. Right-click on the stored procedure, then click Modify. In the query window that appears, change the SQL command from 'ALTER' to 'CREATE,' and rename the procedure from 'sppSalesMonitor_Modified' to 'spcpSalesMonitor.'IGWQFmYQYZtzMr2SyMEYsEQ03Y0SYu4e.png?access_token=snx3tw-rqcvxwnlgi-a4d652e1891cd6b0ae5999b61ca18cfa51d9c427

3. Create the desired new functionality. In the case of the procedure sppSalesMonitor_Modified, additional functionality has already been included, and simply needs to be un-commented. PNR9Ij060tFucyGAbzxkhWCbYsQmpThX.png?access_token=snx3tv-xldcjjitfx-ceb0aa762bef15d05cc7448a17bf0b275088dd6f


4. Execute the changes to create the custom procedure. The new SPCP will now be used in place of the default procedure.

Using a Default Procedure as a Template

Most default procedures with support for an SPCP do not have a predefined template with additional functionality. For these procedures, a custom procedure can be created from the default procedure, which can be modified further for new functionality.

1. Similar to step 1 from above, choose a stored procedure with a code call to an SPCP. For this example, we will use the stored procedure sppUpdateDW.TjIg7DM3762vTMzLPXj6U13Dlkn7ZClx.png?access_token=snx3tu-hqxmjdorkl-67e3455ea8518fe42d980b061c30b0da760a3163


2. Following the 2nd step from above, right-click on the stored procedure, then click Modify. In the query window that appears, change the SQL command 'ALTER' to 'CREATE,' and rename the procedure from 'sppUpdateDW' to 'spcpUpdateDW.'

MwZtif8Bl1emayd191SCBcfoLMKHxKSN.png?access_token=snx3tu-dbcrwzronp-64346bb213a2349228b3dd82dcfa1cbf336cd303

3. To avoid a nesting (infinite loop) error, remove the code call to the SPCP. Failure to remove this will result in the procedure continuously looping back into itself until SSMS recognizes the nesting error and cancels the SQL transaction.0Uj1xuuRHRcfpk2FYv04MHDDMg9L01Hm.png?access_token=snx3tz-qfzyfjeltm-bbd5e0924d58b8a841a2edd8b8762fe72f8887b0


4. Write the desired functionality changes.

5. Execute the changes. The newly created custom procedure will now be used in place of the default.

Reverting Back to a Default Procedure

To stop using a custom procedure and revert back to SalesPad's default procedure, right-click on the desired custom procedure and click Rename.poMtr7RmPo0UXB0D1ydNn907eUNCwEZn.png?access_token=snx3tz-ndsbpypfpv-c2ae2e413909f7a6b8b32b34ced2f59929f31877

Add the text ".bak" to the end of the procedure name, indicating that the custom procedure is now a backup.oDQQXVmr6qyXFM5BHpgwSGGaevKtvnQs.png?access_token=snx3tz-yqiibfqlzg-934219c55cdd9328967fb60dcd72328229d0f14c

Renaming the procedure effectively changes its identity, causing the default procedure to no longer "see" the existence of a matching custom procedure. To begin using the custom procedure again, simply rename it, removing the ".bak."

Viewing Custom Procedures in SalesPad

To see a list of all the custom procedures currently in place, open the SQL Custom Procedures module from the main menu. The list of custom procedures appears in the left grid, and the SQL code for the selected procedure appears on the Object Detail window to the right.

Ptupfy2gno2uxlvVKRnjzCKGZPDvrvdm.png?access_token=snx3tt-jnmvmwazcm-209860965dd96db057facac843aca1cd66739992

Security

SQL Custom Procedures - Grants access to the module to observe existing custom procedures.

Helpful Unhelpful