How to copy the URL to clipboard using client script?

meetanand7
Tera Contributor

Hi,

I am trying to pass the URL to clipboard by using the attached code in client script, but it works in IE browser and not for Chrome. Could you please suggest what change I can do on this code for working in Chrome browser?

find_real_file.png

1 ACCEPTED SOLUTION

Domenic Horner
Tera Expert

Hi there,



I have tested the following code in IE 11, Chrome 62, and Firefox Quantum 57.



function onSubmit() {


      var instanceName = "something";


      var incidentURL = 'https://' + instanceName + '.service-now.com/incident.do?sys_id=' + g_form.getUniqueValue();


      copyToClipboard(incidentURL);


}



ServiceNow provide this "copyToClipboard" function that can be used, which will cause the "Copied to clipboard" message within servicenow.


find_real_file.png



You could also use the code located on this PasteBin to accomplish the same thing silently. function onSubmit() { var instanceName = "something"; var incidentURL - Pastebin.com



Setup in Client Script as follows:


find_real_file.png


View solution in original post

9 REPLIES 9

Chandu Telu
Tera Guru
Tera Guru

HI   Ananad,



Could you please provide the more information on your requirement


The SN Nerd
Giga Sage
Giga Sage

Most lists and breadcrumbs already have this functionality via the context menu.



What is your business requirement?



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

meetanand7
Tera Contributor

Hi,



Our business requirement is to pass the URL to clipboard when the field is updated, so we are trying to do that from the client script with the above mentioned code.


The SN Nerd
Giga Sage
Giga Sage

That is the technical requirement.



What business problem is this solving?



You can copy the URL to clipboard from the context menu on any form



find_real_file.png



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022