[daisy] Programmatically create a link (VariantKey)

Paul Focke paul at outerthought.org
Tue Dec 5 01:16:25 CST 2006


On Monday 04 December 2006 21:58, Robert Cecil wrote:
> Hi,
>
> In one of my flow scripts I am calling into the Repository to connect
> two instances of documents. I have mapped a field in one of my doc
> types as a Link to the second doc type via a query (documentType =
> second type). Programmatically, I am creating an instance of both,
> saving the second (the target of the link), and calling a setField()
> method on the first, passing in the instance variable of the second
> as a parameter. When I run this form I get:
>
> Expected was a link (org.outerj.daisy.repository.VariantKey) but got
> a org.outerj.daisy.repository.commonimpl.DocumentImpl
>
> How do I 'wrap' the document instance with a Link? I could not find a
> createLink(Document doc), createVariantKey(), or createLink() method
> in the API.
>
> Thanks
>
> Rob Cecil


Hi, 

The link field expects a variant key.  It seems like you are passing the 
entire document.  Use the getVariantKey() method to get the variant key.  

So in your flowscript you'll have something like this : 

var document = repository.createDocument(...);
var linkTargetDocument = repository.createDocument(...);
// do stuff
linkTargetDocument.save();
document.setField("linkField", linkTargetDocument.getVariantKey());
document.save();

hth,

Paul


More information about the daisy mailing list