Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

x.teaser = substring({$x.body$},1,50)

Is it possible to populate the teaser field with the first 50 (or how-ever-many) characters of the body?

Or... to populate a table cell with the first 50 chars of the body, without bothering with the teaser field?

Many thanks!

-Bob

Bob Bloom
Sunday, June 15, 2003

It's not possible using CityScript alone--could be done using CityScript in combination with Javascript.

David Burch
Sunday, June 15, 2003

If this is a one-time thing, you could do it within Access as an update query. If it is one-time, and you have Access 2000/XP and need instructions, holler.

Mike Gunderloy
Sunday, June 15, 2003

David, Mike,

Thank you for your replies :-)

David: what would the js script look like?

Mike: Yes, I thought that too, using Access directly. No, it wouldn't be a one-time thing. I'd rather not use Access, because I'd have to build a mini-application.

Using Access is an interesting idea. I'm interested to see what the VB/SQL code looks like.

So Mike, if you have the code to perform this "one off" operation, please post!

-Bob

Bob Bloom
Sunday, June 15, 2003

Actually, on reflection it would be very difficult to do with an Access query, because the article body is stored in an OLE object field.

However, you can certainly do it in VB by extracting the contents of that field, using string functions to massage the data, and then write it into the teaser.

I've made the source code to CopyBoy 1.0 available at http://www.larkware.com/Products/LarkwareCopyBoy.html . If you spelunk in there, you'll see how to work with the Body field and other internals of the CityDesk database.

Mike Gunderloy
Sunday, June 15, 2003

Mike,

Thank you for your reply.

I downloaded your source code -- thanks!

I tried this js:

{$ forEach x in (keywordContains "test") $}
<SCRIPT LANGUAGE="JavaScript">
var bbody = {$ x.body $};
var ttext = bb.substring(0,50)
document.writeln(ttext);
</script>

Why doesn't this script work?

Bob Bloom
Monday, June 16, 2003

Continuing to play...

This js works:

{$ forEach x in (keywordContains "test") $}
<SCRIPT LANGUAGE="JavaScript">
var bb = "{$x.teaser$}";
document.writeln(bb);
</script>
{$ next $}

{$x.teaser$} works, {$x.filedDate$} works.

{$x.author$}, {$x.body$}, {$x.headline$} does not work. Am I doing something wrong, or do some CD fields not work in js?

Bob Bloom
Monday, June 16, 2003

*  Recent Topics

*  Fog Creek Home