ADS script editor vs action runtime differences and debugging

63 views
Skip to first unread message

Rob Atkinson

unread,
May 10, 2022, 7:56:38 PM5/10/22
to TopBraid Suite Users
HI I have a script that behaves as expected in the script  editor but when run as a resource action behaves differently.

two things

 - a script that extracts some data from an asset collection and then inserts it into a different asset collection works from the script editor, but when run as a resource action doesnt complain or  but the data doesnt show up in the target graph.  (The function is tagged as dash:canWrite true BTW)

and  simpler case I noticed:

script  assigns a string to a variable using 

thing = `string template`

when I run console.log(thing) in the script editor it shows, as expected:
"string template"

but when I run this same code in an ADS resource action it renders it as 
"[Object object]"


And finally:
 - is there a way of invoking the resource action directly from the script editor 
 - is there any way of using the script debugger from a resource action, commit or other trigger ? 

Holger Knublauch

unread,
May 10, 2022, 8:17:37 PM5/10/22
to topbrai...@googlegroups.com

On 2022-05-11 9:56 am, Rob Atkinson wrote:
> HI I have a script that behaves as expected in the script  editor but
> when run as a resource action behaves differently.
>
> two things
>
>  - a script that extracts some data from an asset collection and then
> inserts it into a different asset collection works from the script
> editor, but when run as a resource action doesnt complain or  but the
> data doesnt show up in the target graph. (The function is tagged as
> dash:canWrite true BTW)
One potential difference could be the type of the variable focusNode.
Are you using that variable in your scripts?
>
> and  simpler case I noticed:
>
> script  assigns a string to a variable using
>
> thing = `string template`
>
> when I run console.log(thing) in the script editor it shows, as expected:
> "string template"
>
> but when I run this same code in an ADS resource action it renders it as
> "[Object object]"
Hard to say without seeing the surrounding code. But just doing thing =
... may be a variable scope problem. Have you tried using *let* thing =
... instead, to make sure the variable is locally scoped?
>
>
> And finally:
>  - is there a way of invoking the resource action directly from the
> script editor

No but you could place the body of the resource action into a helper
function with a globally unique name and put that into a
dash:IncludedScript. For example

function myResourceAction(resource) { ... }

and then invoke myResourceAction(resource) from the Script Editor panel.
Or attach it to a class as a ShapeScript if you prefer OO programming style.

>  - is there any way of using the script debugger from a resource
> action, commit or other trigger ?

No, this would be nice but quite hard to implement and get right. You
can imagine that running the debugger is already quite a low-level
operation... But maybe the above trick will help you debug this from the
Script Panel. All you may want to add are some guard clauses to verify
that the argument (resource/focusNode) have indeed the right type.

Holger


Rob Atkinson

unread,
May 10, 2022, 8:39:53 PM5/10/22
to TopBraid Suite Users

Am not using the focus node - as its an action on the graph as a whole (attached to ontology as per suggestion in documents) 

am using let thing =

I can try another level of wrapping - I was only able to make functions visible globally using *.api.ttl   - 

 if I declare the functions as dash:IncludedScript they fail to find the global helper functions I declared in a *.api.ttl file.   Importing this function set graph into the resource script graph didnt help:

threw "ReferenceError: "dgf" is not defined"   (dgf. is defined and can access its functions via SPARQL and script editor)

The only reference to ShapeScript I could find searching the 7.2 documentation was

"On saving, EDG will automatically create an instance of type dash:ShapeScript which is attached to the selected node shape. This will ensure that the next time the node shape is selected, the defined function is shown in the shape script panel."

So to attach it to the ontology to test that way I would declare

   owl:Ontology dash:ShapeScript my:action

instead of 
    owl:Ontology  dash:resourceAction my:action 

?

Rob Atkinson

unread,
May 10, 2022, 9:05:35 PM5/10/22
to TopBraid Suite Users
oops - obviously dash:ShapeScript is a type not a predicate - i've got myself mixed up here...  how do you attach to the nodeshape?  The predicate isnt in the docs AFAICT

Rob Atkinson

unread,
May 10, 2022, 9:09:26 PM5/10/22
to TopBraid Suite Users
ahh - its dash:shapeScript - but requires a different syntax - maybe thats what it is hiding as an error when run as a resource script... 

Holger Knublauch

unread,
May 10, 2022, 9:31:22 PM5/10/22
to topbrai...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/efb42514-2b48-40d2-8e06-4a6479eaaf65n%40googlegroups.com.

Rob Atkinson

unread,
May 10, 2022, 9:39:51 PM5/10/22
to TopBraid Suite Users
yes

but this fails when I throw it into the script editor (i'm in a data graph - i dont have an ontology asset collection for the OWL ontology )

class extends owl_Ontology { 
    createDeltas() { 
        return ('worked')
    }
}

owl_Ontology.createDeltas() ;

=> 

"Cannot evaluate Script: org.graalvm.polyglot.PolyglotException: SyntaxError: ADSGenerated-3f177094-235f-4d67-9ac8-fef60e3b2cc9.js:3605:0 Expected { but found } } ^"

Holger Knublauch

unread,
May 11, 2022, 2:27:51 AM5/11/22
to topbrai...@googlegroups.com

Works for me, for any instance of owl_Ontology - not the class itself:

Holger

Rob Atkinson

unread,
May 11, 2022, 2:53:56 AM5/11/22
to topbrai...@googlegroups.com
ahh the typecast!

_______________________________________________________
 
kind regards
Rob Atkinson
Lead Ontologist, Knowledge Architect at SURROUND Australia Pty Ltd
Address   Level 9, Nishi Building, 2 Phillip Law Street; New Acton Canberra Australia 2601
Phone     +61 419 202 973
Email      rob.at...@surroundaustralia.comWebsite   https://www.surroundaustralia.com

Enhancing Intelligence Within Organisations

delivering evidence that connects decisions to outcomes

Copyrights:

SURROUND Australia Pty Ltd is the copyright owner of all 
original content and attachments.
All rights reserved. 
Confidentiality Notice:
The contents of this e-mail are confidential to the ordinary user 
of the e-mail address to which it is addressed, and may also be 
privileged. If you are not the addressee of this e-mail, you may 
not copy, forward, disclose, or otherwise use it or any part of it 
or its attachments in any form whatsoever. If you have received 
this e-mail in error, please e-mail the sender by replying to this 
message.



You received this message because you are subscribed to a topic in the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/topbraid-users/wgR411uTzUM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/34358f3c-5311-d7a5-8d10-4986ad7c5480%40topquadrant.com.
Reply all
Reply to author
Forward
0 new messages