Procedures: Difference between revisions

From nuBuilderForte
Jump to navigation Jump to search
 
(39 intermediate revisions by 4 users not shown)
Line 1: Line 1:
Back to [[Documentation]]
= Introduction =
nuBuilder Forte can create Procedures.
nuBuilder Forte can create Procedures.


A Procedure is PHP code run to manupulate the database.
A Procedure is PHP code run to manipulate the database.




=Building a Procedure=
=Building a Procedure=


These Procedures are written in PHP to do things to the database directly.
Procedures are written in PHP to do things to the database directly.


Here are 2 examples of where a Procedure can be used.
Here are 2 examples of where a Procedure can be used.
#To create the [[Reports#Table|table]] used in a [[Reports|Report]].
#To create the [[Reports#Table|table]] used in a [[Reports|Report]].
#Update a warehouse table after an invoice is created in nuBuilder.
#Update a stock table after an invoice is created in nuBuilder.


==Code==
==Code==
A unique code for this Procedure.
A unique code for this Procedure.
A Procedure with the code '''nuStartup''' will run automatically, immediately after a successful login.


==Description==
==Description==
Line 19: Line 25:


==Group==
==Group==
A field that can be used to help organise Procedures in a list.
A field that can be used to help order Procedures in a list.


==Launch From==
==Launch From==
A Launch Form will allow..
This is only necessary if you need it to...
 
*Run it from the Run Procedure Button.
*Reference [[Hash_Cookies|Hash Cookies]] from a certain Edit Form.
 
It can still be used by [[PHP#nuProcedure|nuProcedure()]].
 
A Launch Form will allow...
 
*The user to define the information to be used by the Procedure.
*The user to define the information to be used by the Procedure.
*Run the Procedure from an [[Action Button]] at the top of the [[Forms|Form]].
*Run the Procedure from an [[Navigation#Action_Buttons|Action Button]] at the top of the [[Forms|Form]].
 
==Run==
==Run==
*In a new window - Appears in a new window much the same as a [[Reports|Report]].
*In a new window - Appears in a new window much the same as a [[Reports|Report]].
*Hidden - This runs behind the scenes but can display a result using [[PHP#nuDisplayMessage|nuDisplayMessage]]
*Hidden - This runs behind the scenes but can display a result using PHP's print or echo statements.


==PHP==
==PHP==
A Textarea containing PHP code.
A Textarea containing PHP code.


This code can also use [[Hash Variables]] that will help you customise nuBuilder.
This code can also use [[Hash Cookies]] that will help you customise nuBuilder.


To edit this, double click on the Textarea and you will open [[Ace Editor]] in a full screen.
To edit this, double click on the Textarea and you will open [[Ace Editor]] in a full screen.
==PHP Library==
This subform allows you to add other previously created Procedures to be run when ever this Procedure is.


=Running A Procedure=
=Running A Procedure=
There are 2 ways to launch a Procedure.
There are 2 ways to launch a Procedure.
#Click the '''Run Procedure''' Button on the Setup Tab of the Home Form.
#Click the '''Run Procedure''' Button on the Setup Tab of the Home Form.
#Create a Button with a custom click event to run [[Javascript#nuRunHiddenPHP|nuRunHiddenPHP]] or [[Javascript#nuRunPHP|nuRunPHP]].
#Create a Button with a custom click event to run [[Javascript#nuRunPHPHidden|nuRunHiddenPHP]] or [[Javascript#nuRunPHP|nuRunPHP]].


=Adding PHP Elsewhere=
=Adding PHP Elsewhere=
Line 48: Line 60:
PHP can be added to run in different places on [[Forms]] or [[Objects#Lookup|Lookups]].
PHP can be added to run in different places on [[Forms]] or [[Objects#Lookup|Lookups]].


These events are used to do different customisable tasks.
These events are used to do different customisable tasks and are run at specific times.


'''Yes''' and '''No'''  is decided by [[PHP#nuDisplayError|nuDisplayError()]] in the flowchart below.
[[File:EventFlow.PNG|800px]]
==Forms==
==Forms==
Generally each event is used for different purposes.
Generally each event is used for different purposes.
Line 55: Line 71:
===Before Browse===
===Before Browse===
*Create a temp table to use as the browsable table.
*Create a temp table to use as the browsable table.
*Add Javascript to the Browse Form with [[PHP#nuAddJavascript|nuAddJavascript()]].
*Add JavaScript to the Browse Form with [[PHP#nuAddJavascript|nuAddJavaScript()]].
*[https://forums.nubuilder.cloud/viewtopic.php?f=31&t=10939 Forum Post]: Added nuOnProcessBrowseRows() in nuBuilder v4.5 on 2021-04-01
** Example: Replace all 1 in column 1 with a ✓ character.
<pre>
function nuOnProcessBrowseRows {
 
  foreach ($f->browse_rows as &$row) {
      if ($row[1] === '1') {
        $row[1] = '✓';
      }
  }
 
}
 
</pre>


===Before Edit===
===Before Edit===
*Add Javascript to the Edit Form with [[PHP#nuAddJavascript|nuAddJavascript()]].
*Add JavaScript to the Edit Form with [[PHP#nuAddJavascript|nuAddJavascript()]].
 
===Before Save===
===Before Save===
*Check if saving is allowed.
*Validate data entry.
*Validate data entry.
===After Save===
===After Save===
*Update other tables.
*Update other tables.
===Before Delete===
===Before Delete===
*Check if deletion is allowed.
*Check if deleting is allowed.
*Update other tables.
*Update other tables.


Line 73: Line 106:


===After Browse===
===After Browse===
*Populate other Objects on the Edit Form.
This runs after a [[Objects#Lookup|Lookup Object]] is changed.
 
*Populate other Objects on the Edit Form with [[PHP#nuSetFormValue|nuSetFormValue()]].

Latest revision as of 10:06, 25 April 2024

Back to Documentation

Introduction

nuBuilder Forte can create Procedures.

A Procedure is PHP code run to manipulate the database.


Building a Procedure

Procedures are written in PHP to do things to the database directly.

Here are 2 examples of where a Procedure can be used.

  1. To create the table used in a Report.
  2. Update a stock table after an invoice is created in nuBuilder.

Code

A unique code for this Procedure.


A Procedure with the code nuStartup will run automatically, immediately after a successful login.

Description

The description of this Procedure.

Group

A field that can be used to help order Procedures in a list.

Launch From

This is only necessary if you need it to...

  • Run it from the Run Procedure Button.
  • Reference Hash Cookies from a certain Edit Form.

It can still be used by nuProcedure().

A Launch Form will allow...

  • The user to define the information to be used by the Procedure.
  • Run the Procedure from an Action Button at the top of the Form.

Run

  • In a new window - Appears in a new window much the same as a Report.
  • Hidden - This runs behind the scenes but can display a result using PHP's print or echo statements.

PHP

A Textarea containing PHP code.

This code can also use Hash Cookies that will help you customise nuBuilder.

To edit this, double click on the Textarea and you will open Ace Editor in a full screen.

Running A Procedure

There are 2 ways to launch a Procedure.

  1. Click the Run Procedure Button on the Setup Tab of the Home Form.
  2. Create a Button with a custom click event to run nuRunHiddenPHP or nuRunPHP.

Adding PHP Elsewhere

PHP can be added to run in different places on Forms or Lookups.

These events are used to do different customisable tasks and are run at specific times.

Yes and No is decided by nuDisplayError() in the flowchart below.


EventFlow.PNG

Forms

Generally each event is used for different purposes.

Before Browse

  • Create a temp table to use as the browsable table.
  • Add JavaScript to the Browse Form with nuAddJavaScript().
  • Forum Post: Added nuOnProcessBrowseRows() in nuBuilder v4.5 on 2021-04-01
    • Example: Replace all 1 in column 1 with a ✓ character.
function nuOnProcessBrowseRows {

   foreach ($f->browse_rows as &$row) {
      if ($row[1] === '1') {
         $row[1] = '✓';
      }
   }

}

Before Edit

Before Save

  • Check if saving is allowed.
  • Validate data entry.

After Save

  • Update other tables.

Before Delete

  • Check if deleting is allowed.
  • Update other tables.

After Delete

  • Update other tables.

Lookups

After Browse

This runs after a Lookup Object is changed.