Topic
  • 5 replies
  • Latest Post - ‏2013-03-01T22:26:06Z by SystemAdmin
sai_m
sai_m
24 Posts

Pinned topic Parsing Record Object

‏2013-02-06T04:10:20Z |
Hi All,

Please help me on how I can parse an object of a "Record" data type into a local complex variable. As an example, I have a returned a "Record" result from a DB query and trying to parse the contents of the record into a local complex variable having 3 simple variables.

Thanks Everyone!!
Updated on 2013-03-01T22:26:06Z at 2013-03-01T22:26:06Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Parsing Record Object

    ‏2013-02-07T18:16:51Z  
    The easiest way to do this is to allow the tool to do it for you. Lets Say I have a BO "Student" that has members "firstName", "lastName", and "birthDay". And lets just say, rather annoyingly I have a table of students with columns fname, lname, and bday. I can use the connectors in the system data toolkit and tell them "I want you to give me back a list of 'Student' BO." And hand it the query
    
    select fname as first_name, lname as last_name, bday as birth_day from student_table
    


    Basically as long as the column match the members of the BO (ignoring case and the _ character) then it will do the parsing for you.
    Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
  • sai_m
    sai_m
    24 Posts

    Re: Parsing Record Object

    ‏2013-02-22T21:16:11Z  
    Thanks Andrew! It looks like parsing record objects is same as usual as for other complex objects. For example, if a local variable called as "resultSet" is a "record" object, then it can be parsed into another local variable as tw.local.resultSet.firstName...

    The only difference is the type ahead for sub record objects will not work.. which means we will have to manually type ".firstName" after tw.local.resultSet..

    Thanks,
    Sai Pavan Kumar.
  • kolban
    kolban
    3322 Posts

    Re: Parsing Record Object

    ‏2013-02-24T04:03:05Z  
    • sai_m
    • ‏2013-02-22T21:16:11Z
    Thanks Andrew! It looks like parsing record objects is same as usual as for other complex objects. For example, if a local variable called as "resultSet" is a "record" object, then it can be parsed into another local variable as tw.local.resultSet.firstName...

    The only difference is the type ahead for sub record objects will not work.. which means we will have to manually type ".firstName" after tw.local.resultSet..

    Thanks,
    Sai Pavan Kumar.
    Interesting. This now raises the question "What is the Record data type?" and how is it meant to be used?
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Parsing Record Object

    ‏2013-02-24T06:08:05Z  
    The easiest way to do this is to allow the tool to do it for you. Lets Say I have a BO "Student" that has members "firstName", "lastName", and "birthDay". And lets just say, rather annoyingly I have a table of students with columns fname, lname, and bday. I can use the connectors in the system data toolkit and tell them "I want you to give me back a list of 'Student' BO." And hand it the query
    <pre class="jive-pre"> select fname as first_name, lname as last_name, bday as birth_day from student_table </pre>

    Basically as long as the column match the members of the BO (ignoring case and the _ character) then it will do the parsing for you.
    Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
    Assuming you are getting results as XMLElement.

    tw.local.XYZ = tw.system.serializer.fromXml('<variable type="<variableType>[]">'+tw.local.results.firstChild.firstChild.getText()+'</variable>');
  • SystemAdmin
    SystemAdmin
    7615 Posts

    Re: Parsing Record Object

    ‏2013-03-01T22:26:06Z  
    • kolban
    • ‏2013-02-24T04:03:05Z
    Interesting. This now raises the question "What is the Record data type?" and how is it meant to be used?
    "Record" is really "I want to have a somewhat structured piece of data to hand around, but I really don't want to define it for you". So basically if you create a variable of type "Record" you can do

    
    tw.local.myRecord.anyMemberNameIWant=
    "Whatever"; tw.local.myRecord.randomComplexMember=
    
    new tw.object.Student(); …
    


    And it will work. But the problem is that you really have no control over this construct. When I accept a defined business object as in input, I know what its members are. If I were to say "Just give me a record", now I have no good way to really know what the members of that are. It adds a bunch of flexibility, but at the cost of clarity and understanding.

    Basically this is another way to have an ANY type…. And just like ANY you can assign them between various "BusinessObjects" as long as the underlying members exactly match the BusinessObject's members. Or at least that should work. I've never had a compelling reason to try….

    Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com