Page 1 of 1

How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 12:44 am
by xyz
I have saved a value in a custom property of a card (cpOwner). In a list on the card (lstOwner), I want to select the item in the list that matches the data in the custom property. How do I do that?

All of these efforts have failed with an error:

Code: Select all

   
   on preOpenCard
   	get the cpOwner of this card
   	--set the hilited of field "lstOwner" to it
   	--select it in field "lstOwner"
  	--select the cpOwner of field "lstOwner"
  end preOpenCard
BTW, I commented out the failed efforts in my code. That's why they are commented out here.

Thanks in advance.

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 2:09 am
by mwieder

Code: Select all

set the hilitedLine of field "lstOwner" to it

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 2:54 am
by xyz
Thanks for the reply.

Unfortunately hilitedLine returns (or sets) an item in a list using the line number. My custom property is a string. :( I want to match the string in the list with the string in my custom property. I was not at all clear on that in my first post. Sorry.

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 3:15 am
by mwieder
Probably the lineOffset function is going to give you the best results.
That will give you a line number which you can then plug into the hilitedLine command.

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 3:29 am
by xyz
That did it.

Code: Select all

   get the cpOwner of me
   put it into theOwner
   set the hilitedLine of field "lstOwner" to lineOffset(theOwner,field "lstOwner")
Many thanks!! :D

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 3:50 am
by mwieder
Yay! :D
If you want to get really fancy you could even shorten that to a single line

Code: Select all

set the hilitedLine of field "lstOwner" to lineOffset(the cpOwner of me,field "lstOwner")

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 10:03 am
by Klaus
Hi xyz,

welcome to the forum!

Here some great learning resources for the basics of LC, maybe start with "Controls" :-)
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 5:28 pm
by xyz
Cool "compression" to a single line!! :P

Thanks for the welcome, Klaus. I'll check out the link.

Re: How to programmatically select list item from value of a custom property

Posted: Sun Mar 29, 2020 5:36 pm
by Klaus
Here another "compression":

Code: Select all

...
## get the cpOwner of me
## put it into theOwner
put the cpOwner of me into theOwner
...
No need to use GET and IT here first! :D