Using Data Dictionaries in Business Processes: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
Marco (talk | contribs)
New page: ==Why not direct file buffer access== In many cases, direct file buffer access would be simpler. But, it goes around your carefully constucted validation rules etc. Surely you can duplicat...
 
No edit summary
Line 5: Line 5:
===Simple Example===
===Simple Example===
The simplest example is where we save new records in a table that does not have a parent file.  
The simplest example is where we save new records in a table that does not have a parent file.  
 
<pre>
   Function CreateCustomer String sName String sEmail
   Function CreateCustomer String sName String sEmail
       Handle hServer
       Handle hServer
Line 22: Line 22:
       Function_Return iError
       Function_Return iError
   End_Function
   End_Function
 
</pre>
This save takes all the Data Dictionary rules into account that are linked to the validation and save mechanisms. So is much better than direct file access (using clear, move and saverecord).<br>
This save takes all the Data Dictionary rules into account that are linked to the validation and save mechanisms. So is much better than direct file access (using clear, move and saverecord).<br>
But this simple example does not work if the record has a relationship to a parent table. It is also not using any field settings like capslock.
But this simple example does not work if the record has a relationship to a parent table. It is also not using any field settings like capslock.
Line 28: Line 28:
===Relationships===
===Relationships===
When the record you wish to create has a relationship to a parent record, you have to first find the parent record, just like you do in a view, prior to issueing the save. Lets create inventory for an existing vendors.
When the record you wish to create has a relationship to a parent record, you have to first find the parent record, just like you do in a view, prior to issueing the save. Lets create inventory for an existing vendors.
 
<pre>
   Function CreateInventoryItem Integer iVendor_ID String sItem_ID String sDescription
   Function CreateInventoryItem Integer iVendor_ID String sItem_ID String sDescription
       Boolean bNotOk
       Boolean bNotOk
Line 48: Line 48:
       Function_Return iError
       Function_Return iError
   End_Function
   End_Function
 
</pre>
This works nicely by finding the parent Vendor record, then create the new item.
This works nicely by finding the parent Vendor record, then create the new item.
===Field Settings===
===Field Settings===
Line 56: Line 56:


==Deleting records==
==Deleting records==
[[Category:Data Dictionaries]]

Revision as of 02:02, 30 November 2007

Why not direct file buffer access

In many cases, direct file buffer access would be simpler. But, it goes around your carefully constucted validation rules etc. Surely you can duplicate these rules, but the whole idea of a Data Dictionary class is that the behaviour is inherited to all objects that initiate a record manipulation.

Saving new records

Simple Example

The simplest example is where we save new records in a table that does not have a parent file.

  Function CreateCustomer String sName String sEmail
      Handle hServer
      Boolean bNotOk
      Integer iError
      Move (Customer_DD) To hServer
      Send Clear of hServer
      Set Field_Changed_Value Of hServer FIELD Customer.Name To sName
      Set Field_Changed_Value Of hServer FIELD Customer.EMail_Address To sEmail
      Get Request_Validate of hoServer to bNotOk
      If (bNotOk) Move -1 To iError 
      Else Begin
          Send Request_Save Of hServer
          If (Err) Move -2 To iError
      End
      Function_Return iError
  End_Function

This save takes all the Data Dictionary rules into account that are linked to the validation and save mechanisms. So is much better than direct file access (using clear, move and saverecord).
But this simple example does not work if the record has a relationship to a parent table. It is also not using any field settings like capslock.

Relationships

When the record you wish to create has a relationship to a parent record, you have to first find the parent record, just like you do in a view, prior to issueing the save. Lets create inventory for an existing vendors.

  Function CreateInventoryItem Integer iVendor_ID String sItem_ID String sDescription
      Boolean bNotOk
      Integer iError
      Send Clear of Invt_DD
      // Find the parent record. This will also prime the foreign key (Invt.Vendor_ID)
      Send Clear of Vendor_DD 
      Move iVendor_ID To Vendor.ID
      Send Find to Vendor_DD Eq 1
      // Set the other fields
      Set Field_Changed_Value Of Invt_DD FIELD Invt.Item_ID To sItem_ID
      Set Field_Changed_Value Of Invt_DD FIELD Invt.Description To sDescription
      Get Request_Validate of Invt_DD to bNotOk
      If (bNotOk) Move -1 To iError 
      Else Begin
          Send Request_Save Of Invt_DD
          If (Err) Move -2 To iError
      End
      Function_Return iError
  End_Function

This works nicely by finding the parent Vendor record, then create the new item.

Field Settings

In the above example the Item_ID is not set to capslock. This is because the capslock is actually not part of the validation or save, it is a setting used by the dbForm and other visual objects. If we want to also apply these settings, we need to do some more.

 Example required

Updating existing records

Deleting records