Copy to Clipboard

Hi

What we need is a possibility that a user can click on a button and then has some information in the clipboard so he can paste it in other solutions (like for example in an e-mail or word-document). In the Servoy-Smart-Client this works with “application.setClipboardContent(string)”, but this doesn’t work in NG-Client.

How can we handle this in NG-Client? Are there any components or services that can handle this? There are JavaScript-Libraries out there that can do this (like for example “https://clipboardjs.com”), but I was wondering, if Servoy has some stuff like this already built in?

Best
Roland

Hi Roland,

currently that’s only available when you run NG client of the NGDesktop client.

However, a while ago I’ve put together a small service which should do the job.
Haven’t had time to properly finish/test it, but if you feel like it: give it a spin[attachment=0]solClipboard.zip[/attachment]

Hope this helps

solClipboard.zip (1.57 KB)

Thank you very much, Marc. I’ll try your service and give feedback!

Best
Roland

Works exactly as I need it! Tested in Chrome (87.0.4280.88), Firefox (83.0) and MS Edge (87.0.664.60).

Thanks again, Marc

Best
Roland

mboegem:
Hi Roland,
currently that’s only available when you run NG client of the NGDesktop client.
However, a while ago I’ve put together a small service which should do the job.
Haven’t had time to properly finish/test it, but if you feel like it: give it a spin[attachment=0]solClipboard.zip[/attachment]
Hope this helps

Hi Marc,
I just tried your ‘service’ in the latest version of Servoy [2023.6.0.3883], but unfortunately it does not work in either TiNG or NG client.
I would really appreciate it if you might be able to have a look at what you created and see if you can tweak it to work with this (& future) versions, as I am currently migrating a new client from a very old FileMaker Pro solution and part of that old solution had scripts that copied things like names & address to the clipboard to allow easy pasting in to Word (or whatever) documents and the Servoy “application.setClipboardContent(‘text’)” command doesn’t work in either also (even though Wiki states it does in NG client).
I’ve put in the obvious workaround of a ‘dialog’ with the specific text in a text area for manual copy/paste, but it’s not ideal ;-)
Thanks
Rafi

Hi Rafi,

As you mentioned Servoy does have its own ‘copy to clipboard’ function.
I’ve tried that and it works for me in 2023.6 (TiNG), but also in NG for older versions.
However, there’s a ‘gotcha’ here, the command will only work if being called from a button on a form, so the form must be focussed.
If you open the browser inspector and look in the console, you can see errors appearing if you call the command from the command console.

As for your request on my NG-service:
I don’t believe I will be continuing work on that.
Like I wrote back in 2020:

Haven’t had time to properly finish/test it, but if you feel like it: give it a spin

At that time I don’t believe application.setClipboardContent did work in NG and now it does it feels like putting effort in something that doesn’t add more value.
Hope you can understand that.

Nevertheless, I think my NG-service should still work for NG (not TiNG):
It has been a while, but I believe my clipboard-service as well as the native application.setClipboardContent command do a similar thing depending on the browser and version.
When I grabbed some code and wrapped this into the service, I bumped into a ‘not working’ service myself when calling the command from command line: the command needs to be executed from a button on the form.

Hope this helps and if you have any particular use cases which are not currently supported, I think you should raise a support request at support.servoy.com

Hi Marc,
thanks for your reply.
After reading it, I checked console errors & then ‘googled’ message and now realise that the issue is SAFARI!
There seems to be a ‘bug’ that stops the clipboard command from working (mainly reported by developers trying to auto-play videos).
It works fine in Chrome & Firefox, but both myself & the client use (macOS) Safari as default browser, so using another browser for Servoy is not ideal…
I will probably have to raise a support case for this now (& carry on with current ‘fix’ of manual copy/paste from a dialog)
Thanks
Rafi

Just for clarification, application.setClipboardContent() works on NG Client Web (with the exception of Safari), and in NG Desktop I have to use plugins.ngdesktoputils.setClipboardContent() to set the clipboard, right?

So it’s something like

if (scopes.svySystem.isNGClient() && plugins['ngdesktoputils'] && plugins['ngdesktoputils'].isNGDesktop()) {
	plugins.ngdesktoputils.setClipboardContent(...);
} else {
	application.setClipboardContent(...);
}

to get everyone but safari-users happy?

robert.edelmann:
Just for clarification, application.setClipboardContent() works on NG Client Web (with the exception of Safari), and in NG Desktop I have to use plugins.ngdesktoputils.setClipboardContent() to set the clipboard, right?
to get everyone but safari-users happy?

Hi
I can only comment on Ti/NG web client, but “application.setClipboardContent()” does work on Mac browsers other than Safari…

Asking here first, but if I don’t get an answer will make a new post…
Is there a way to find the ‘browser agent’ when using Ti/NG client, so that I can make my clipboard code use the working function when not in Safari, otherwise use the work-around?
Thanks
Rafi

Hi Rafi,

This should get it:

plugins.ngclientutils.getUserAgent()

Best,
Sean

sean:
Hi Rafi,
This should get it:

plugins.ngclientutils.getUserAgent()

Best,
Sean

Thanks Sean!
It would be great if Servoy could fix this ‘issue’ though ;-)

In case it saves someone 1 minute of coding, (I have a global boolean variable ‘isSafari’)

		var browser_name = plugins.ngclientutils.getUserAgent() ;
		isSafari = (utils.stringPosition(browser_name, 'Safari', 1, 1) >= 1);
		application.output ( 'isSafari ' + isSafari + ' [' + browser_name + ']' );

:D

After chatting with Johan at ServoyCamp, Servoy is making this call at the lowest level

navigator.clipboard.writeText(content) ;

Using that, I found some articles that basically say that to get it to work in Safari you need to use

navigator.clipboard.write(content) ;

Please see these links for more details & I hope that Servoy can update the low level code to fix, assuming this also works for all other browsers ;-)

Thanks
Rafi

As this has still been fixed (as of latest release version [not tested RC], I have created a case for it

I hope it can be pushed in to 2024.3
Thanks

Rafi