Page 1 of 1

reference card in script by field value

Posted: Tue Feb 28, 2023 11:43 am
by CAsba
Hi,
I have a template card that script copies to become a new customer account card. The name of the new card is the customer code. I want to run a button on the new card from another card. I have tried

Code: Select all

send mouseup to btn "new" of cd fld "newcode" of this card
but it doesn't work.
I guess I could do it another way, but I think it would involve more mouse clicks and I want to keep it as user-friendly as possible.
Any ideas how to amend my code to facilitate the send mouseup message to a button on a newly created card whose name is not known (yet) by the system, except as the contents of the field 'newcode'.

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 11:57 am
by Klaus
Hi CAsba,

always use quotes around the message(s) to send:

Code: Select all

send "mouseup" to ...
Put the content of the field into a variable first:

Code: Select all

...
put fld "newcode" into tTargetCard
send "mouseup" to btn "new" of cd tTargetCard
## No needd for "...of this cd" since LC always presumes that you mean the current card if nothing else is specified.
...
Best

Klaus

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 2:06 pm
by CAsba
Hi Klaus, Thanks for that.
Actually, I found another way,

Code: Select all

go to cd "CustomerAccountTemplate"
   clone this card
   set the name of cd "CustomerAccountTemplate" OF STACK "casba accounts - demo" to fld "newcode" of cd "enter new customer"
   send "mouseup" to btn "button1" 
and buuton1 - on the newly created card - does the business!

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 2:11 pm
by Klaus
OK, I had no idea what you wanted to achieve, good you got it working.

Useful hint:
You can directly assign a new name to the cloned object with:

Code: Select all

clone this cd AS "new card name here"

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 2:27 pm
by CAsba
Hi Klaus,
That's VERY useful. Many thanks !

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 6:27 pm
by jacque
When an object is created its id is placed in the "it" variable. So you could also do this :

Code: Select all

clone card x
set the name of it to <whatever>
Edit: Klaus' way is shorter.

Re: reference card in script by field value

Posted: Tue Feb 28, 2023 6:48 pm
by Klaus
Je suis plus "lazy" que toi! :-D

Re: reference card in script by field value

Posted: Wed Mar 01, 2023 4:11 pm
by CAsba
Many thanks, Jacque