Passing datagrid data row to another stack

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Passing datagrid data row to another stack

Post by jalz » Mon Feb 24, 2014 2:44 pm

Hi all,

I need some advice. I'm trying to pass all the data of a single row in my datagrid to a command called "CustomerContactEdit" which is in another stack. I've got the code below, can someone advise me as to where I am going wrong. Its driving me potty. I can seem to extract a field and pass that through, but not the whole row.

The code below is attached to my datagrid which contains the rows of data.

Code: Select all


on mouseDoubleUp
   get the dgHilitedLines of me
   EditRecord it
end mouseDoubleUp

on EditRecord pLineNumber
   local tRecordA, pContactID
   
   put the dgDataOfLine[pLineNumber] of me into tRecordA
   --put tRecordA["contactID"] into pContactID
   
   if pContactID is empty then exit EditRecord
   
   -- I cant seem to get contents of tRecordA to pass to the ContactForm command which is in the CustomerContactEdit
   send "ContactForm " & tRecordA & comma & pLineNumber to the card "CustomerContactEdit" of the stack "CustomerContactEdit" in 1 milliseconds
   
   set the loc of stack "CustomerContactEdit" to the loc of this stack
   modal stack "CustomerContactEdit"
   show stack "CustomerContactEdit"
   
end EditRecord
The code below is the command it is calling and I want to split the data to the various fields on my layout.

Code: Select all

command ContactForm tRecordA, pLineNumber
   put tRecordA["contactID"] into field "fld_contact_id"
   put tRecordA["customerID"] into field "fld_customer_id"
   put tRecordA["title"] into field "fld_title"
   put tRecordA["firstname"] into field "fld_firstname"
   put tRecordA["lastname"] into field "fld_lastname"
   put tRecordA["position"] into field "fld_position"
   put tRecordA["telephone"] into field "fld_telephone"
   put tRecordA["mobile"] into field "fld_mobile"
   put tRecordA["email"] into field "fld_email"
end AB
Thanks to all that help

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Passing datagrid data row to another stack

Post by Klaus » Mon Feb 24, 2014 2:58 pm

Hi Jalz,

do not use THE when addressing objects!
## Bad:
##...fld "a field" of THE cd "card name here" of THE stack "stack222"
## Good:
...fld "a field" of cd "card name here" of stack "stack222"

THE should only be used to address custom properties!
That is not causing your problem, but anyway... :D


To your problem.
You need to pass the NAME of the variable with "send" and not its content:
...
## send "ContactForm " & tRecordA & comma & pLineNumber to the card "CustomerContactEdit" of the stack "CustomerContactEdit" in 1 milliseconds
send "ContactForm tRecordA,pLineNumber" to card "CustomerContactEdit" of stack "CustomerContactEdit" in 1 milliseconds
...


Best

Klaus

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Passing datagrid data row to another stack

Post by bangkok » Mon Feb 24, 2014 3:20 pm

I think you could make your life easier :

1- why using using a command, if only the mousedoubleup is going to use it ? You could put everything in the same script :

Code: Select all

on mouseDoubleUp
   put the dgHilitedLines of me into pLineNumber
   put the dgDataOfLine[pLineNumber] of me into tRecordA
    put tRecordA["contactID"] into pContactID
   if pContactID is empty then exit EditRecord
   
....
....
end mouseDoubleUp
2- you could use a global variable.

3- why... don't you set the content of the fields on the other stack directly from the same script ?

Code: Select all

on mouseDoubleUp
   put the dgHilitedLines of me into pLineNumber
   put the dgDataOfLine[pLineNumber] of me into tRecordA
    if tRecordA["contactID"]  then exit to top
 
 put tRecordA["contactID"] into field "fld_contact_id" of stack "CustomerContactEdit"
   put tRecordA["customerID"] into field "fld_customer_id" of stack "CustomerContactEdit"
   put tRecordA["title"] into field "fld_title" of stack "CustomerContactEdit"
   put tRecordA["firstname"] into field "fld_firstname" of stack "CustomerContactEdit"
 
 set the loc of stack "CustomerContactEdit" to the loc of this stack
   modal stack "CustomerContactEdit"
   show stack "CustomerContactEdit"
end mouseDoubleUp

jalz
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 340
Joined: Fri Sep 12, 2008 11:04 pm

Re: Passing datagrid data row to another stack

Post by jalz » Mon Feb 24, 2014 9:43 pm

Thanks you Guys,

Both of you are awesome. I spent ages trying to get this to work yesterday, still have lots to learn… :D

Post Reply