Announcement

Collapse
No announcement yet.

How to use fileds of a foreign table in header

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use fileds of a foreign table in header

    Hi,

    in layout/header/footer settings of a grid/form it's possible to show a field value of the current table. How can I show a field value from a foreign table?

    Joe

  • #2
    Use a global variable in onappini asign the value for your table

    Comment


    • #3
      Hi alvagar,

      thanks for your help. I'd like to show customers name in header which is in a different table 'customers' in field 'last_name'
      Could you give me a code example?

      Thanks
      Joe

      Comment


      • #4
        In Event ONSCRIPTINI:
        sc_lookup(rs, "SELECT last_name FROM customers where id = {your_id}");

        [v_last_name] = {rs[0][0]};

        Then This variable [v_last_name] put in your header/footer

        Comment


        • #5
          Hi alvagar,

          I tried

          sc_lookup(rs, "SELECT last_name FROM customers where id = {customer_id}");

          [v_last_name] = {rs[0][0]};

          and put [v_last_name] in the header but it shows for every customer only the number "1"

          Whats wrong?
          Joe

          Comment


          • #6
            First test if your sql is Good in SQL Administrator. If ID is Character, It must be in '{customer_id}'.

            Comment


            • #7
              Thank you I got it now. Just forgot to update variable settings in the grid.

              Joe

              Comment


              • #8
                One more question.

                How would be the syntax if I want to show more than only one field? Do I have to define a global variable for each field?
                Does someone have a code snippet?

                Joe

                Comment


                • #9
                  Originally posted by Joe View Post
                  One more question.

                  How would be the syntax if I want to show more than only one field? Do I have to define a global variable for each field?
                  Does someone have a code snippet?

                  Joe
                  Or concat, as you prefer.

                  PHP Code:
                  sc_lookup(rs"SELECT CONCAT (last_name, ' ', first_name) FROM customers where id = {customer_id}"); 
                  or

                  PHP Code:
                  sc_lookup(rs"SELECT last_name, first_name FROM customers where id = {customer_id}");
                  [
                  v_last_name] = {rs[0][0]} . ' ' . {rs[0][1]} ; 
                  /Giuseppe

                  Professional Scriptcase Services
                  Some Customers opinions

                  Comment

                  Working...
                  X