Posting from grid in the source to a grid in the target

GenMap can be used to post the rows entered in a grid in the source Tstruct to  another grid in the target Tstruct. For this the Target Row value in the mapping should be set to zero for the grid fields. See the scenario below to understand grid to grid GenMap posting.

Scenario : Maintaining Employee and Contact details within an organization.

Consider two Tstructs,Employee Master  and Contact Master.Employee master contains employee data. Contact Master captures the address and contact numbers of all people. This table may contain the contact details of employees, customers, suppliers etc. Now, when the employee data is stored, the name, address, phone number and email address fields should be posted into the Contact Master Tstruct.

  • Create the Employee Master Tstruct and  Contact Master Tstruct. The Tstruct definitions are as given below

Employee Master Tstruct

Type Name Caption Properties
Tstruct emp Employee Master TransId = emp
DC dc1 Header TableName=empmaster
InputField Empid Employee Id DataType = Character
DataWidth=15
AllowEmpty=False
AllowDuplicate = False
InputField Name Name DataType = Character
DataWidth=50
AllowEmpty=False
InputField DOJ Date of Joining DataType = Date
DataWidth = 10
InputField Address Address DataType = Character
DataWidth = 50
DC dc2 Details TableName=empmasterdet
AsGrid = True
InputField CPhone Phone DataType = Character
InputField CEmail Email DataType = Character

Contact Master

Type Name Caption Properties
TStruct Cntct Contact Master TransId = Cntct
DC dc1 CMaster TableName=cntctmast
InputField CCode Contact Code DataType = Character
DataWidth=15
AllowEmpty=False
AllowDuplicate = False
InputField CType Contact Type DataType = Character
DataWidth=15
InputField CName Contact Name DataType = Character
DataWidth=50
AllowEmpty=False
InputField CAddress Contact Address DataType = Character
DataWidth = 50
DC dc2 Details TableName=cntctdet
AsGrid = True
InputField CPhone Phone DataType = Character
InputField CEmail Email DataType = Character
  • In the source, i.e Employee Master TStruct, insert a GenMap control.
GenMap in Employee Master

GenMap in Employee Master

  • Set the properties as follows:
Type Name Properties
GenMap Caption = Post from Employee To Contact
Target TStruct = Contact Master
Active = True

Map : Click on the […] button and map details as follows.

To Add mapping click [+] button on top right of the GenMap pop up.

Note : Source from = Field and Target Row = 1 unless otherwise specified

 

Source Target Field
Empid CCode
Source from = Value
Employee
CType
Name CName
Address CAddress
CDesignation CDesignation
CDepartment CDepartment
PhNo CPhone , Target Row = 0
Email CEmail, Target Row = 0

In this example,the contact  phone numbers and email ids are stored as a grid in both the Employees and Contacts form as shown below.

Grid to grid posting

Grid to grid posting

 

Note that the target row is set as 0 for phone and email fields. This will ensure that all rows in the source grid are added as rows into the target grid.

You could also map some field values from the header to a field in a grid in the target. You cannot map fields from a grid in the source to a non grid field in the target.

  • Use a Row Control Field in the map property of  GenMap to control the rows that go from the source to target. Create a field in the source grid as the Row control field. This field should contain T or F. The row from the grid will be posted only if this field contains T. You can use an expression with IIF function to implement a rule.