COMPANY
COMMUNITY
BLOG
HELP
MY ACCOUNT
EN PT ES

Imagen6347E

From GeneXus 8.0 RC: Structured data types (II)

In our last issue, we learned how to define a structured object as well as some of its properties. In this issue, we will see how to use it.

Use of the SDT: loading 
Following the example of the "Client" structured data type, once the SDT has been created,

it is possible to define variables based on it, from any GeneXus object.

This variable can be loaded, for instance, by going through the Data Base using the code: 

For Each 
Where CliID = &CliId 
&Client.Name = CliNam
&Client.Identity = CliDoc
&Client.Nationality= &Nationality
&Client.Address.Company = CliAdd
&Client.Phones.Add(CliPho)
Endfor 

Use of the SDT: loading through XML

The information may also be loaded from an XML, by simply using the &Client.FromXml(&ClientXml) code
Once the XML has been loaded, the client data is obtained by accessing the SDT items, in a clearer way than before, with the Xmlreader data type.
Likewise, the content of an SDT may be saved in xml with: 
&ClientXML = &Client.ToXml() 

The content of the &ClientXml string will be: 
<Client xmlns = "name_Kb">
<Name>CliNam</Name>
<Identity>... </Identity>
<Nationality>... </Nationality>
<Address>
<Company>CliAdd</Company>
<Personal>CliAdd2</Personal>
</Address>
<Phones>
<item> CliPho1 </item>
<item> CliPho2 </item>
</Phones> 

The same string may be generated using the XML data types, but it is much more complex; the following code lines are needed:

&FileXml.opentoString() 
&filexml.WriteNSStartElement('Client', , "name_kb") &filexml.WriteElement('Name', CliNam )
&filexml.WriteElement('Identity', & )
&filexml.WriteElement('Nationality', & )
&filexml.WriteStartElement('Address')
&filexml.WriteElement('Company', CliAdd )
&filexml.WriteElement('Personal', CliAdd2 )
&filexml.WriteEndElement() 
&filexml.WriteStartElement('Phone')
&filexml.WriteElement('Item', CliPho1 )
&filexml.WriteElement('Item', CliPho2 )
&filexml.WriteEndElement() 
&filexml.WriteEndElement() 
&ClienteXML = filexml.resultingString()
&filexml.Close()

Use of the SDT: Supply/Use 

Now we are in a condition to supply/use a clients data in a Webservice. In order to supply the data, you just have to define a procedure with the SOAP call protocol and retrieve a Client-type variable per parameter. In order to use the data, you have to use the WSDL inspector and it will create the required SDT for use. 
The client might also be passed on or received in any other GeneXus object, without the need to access the database. In the past, this meant passing on n parameters, something like: 

Call('WtrabClient', &CliNam, &CliDoc, &CliAdd, &CliPho1, &CliPho2)
Now, this is translated as: 
Call('WtrabCli', &client)

Specification, generation, knowledge manager 

The SDT object is specified through the objects that call it (which have variables based on the structured data type) It is possible to export/consolidate one or more structured data types through the knowledge manager. 

In the next issue of the GeneXus News we will share the definition of more complex structured data types (collections), their properties, and more Webservice cases.

Related
From GeneXus 8.0 RC: Structured Data Types (SDT)
From GeneXus 8.0 RC: Structured Data Types (III)
GeneXus releases its next version