Question

How to use TBox Clipboard to copy JSON content to the clipboard

  • 13 March 2024
  • 3 replies
  • 31 views

Badge

Hello!

I got two modules which send a request and receive a JSON response. After receiving, I want to copy the resource “{RES[LastResponseResource]}” (which reflects the latest received response content) to the clipboard by using “TBox Clipboard”.

The content is defenitely a valid JSON. However, the Scratchbook brings up the error ‘Token is not valid in this context: “ ’. Is it possible to copy the JSON response to the clipboard?

Here a short excerpt of the Testcase I’m trying to get up and running:

Test fails at step “TBox Clipboard”

 


3 replies

Userlevel 3
Badge +1

I just tried this myself (with Tosca 2023.1) and it worked fine. Do you get the same error if you use e.g. TBox Set Buffer to do the same thing?

 

If you haven’t already - try editing the Value column and make sure there’s no extra characters, line breaks etc that might not be obvious from the way Tosca displays the value.

Out of curiosity - what are you planning to do with the response once it’s in the clipboard? As there may be a different way to achieve whatever it is you’re trying to do with it.

Badge

Hello @brendon.russell 

 

You’re right! It works… somehow! For this post, I simplified the example back to the minimal steps it takes to achive my goal: get the JSON response in the clipboard > and the simplified version works very well, due to your comment. Nice nice nice 😅😅😅!!!! Thank you very much!

 

What led to my error is a detour utilizing a buffer, please take a look at this screenshot from the scratchbook:

Additional Step “TBox Set Buffer”

Test looks like this

Name ActionMode     Value
TBox Set Buffer    
lastRes Input {RES[LastResponseResource]}
<Buffername>    
TBox Clipboard    
Value Input {B[lastRes]}

 

So, copying the RES to a buffer and clipping this buffer does not work. Seems, “TBox Set Buffer” is the bad boy in the sequence… 

 

Nevertheless… Thank you very much for your support @brendon.russell ! Kind regards

Userlevel 3
Badge +1

Hello @brendon.russell 

 

You’re right! It works… somehow! For this post, I simplified the example back to the minimal steps it takes to achive my goal: get the JSON response in the clipboard > and the simplified version works very well, due to your comment. Nice nice nice 😅😅😅!!!! Thank you very much!

 

What led to my error is a detour utilizing a buffer, please take a look at this screenshot from the scratchbook:

Additional Step “TBox Set Buffer”

Test looks like this

Name ActionMode     Value
TBox Set Buffer    
lastRes Input {RES[LastResponseResource]}
<Buffername>    
TBox Clipboard    
Value Input {B[lastRes]}

 

So, copying the RES to a buffer and clipping this buffer does not work. Seems, “TBox Set Buffer” is the bad boy in the sequence… 

 

Nevertheless… Thank you very much for your support @brendon.russell ! Kind regards

Ah very sneaky, the actual steps you were using were not the same as your original screenshot ;)

I was able to replicate your issue using the steps above, i.e. buffer the response resource then try to copy the buffered value to the clipboard.

After a little more trial and error, I was able to trigger a similar error with TBox Set Buffer itself. I thinik It must be something to do with the combination of { } and “ characters (and possibly others in your full JSON response), which have specific meaning when used as a Tosca value. Normally you’d have to work hard to escape those characters in the right way so that Tosca treated them as a literal string and didn’t try to parse them as special values.

I guess {RES[]} is designed to cater for those characters so it works, but once that value has been converted to a normal string of text (e.g. by buffering it), you’re probably not going to have any luck trying to use them as a Tosca value.

 

Reply