diff options
author | claw0ry <me@claw0ry.net> | 2024-12-11 13:56:52 +0100 |
---|---|---|
committer | claw0ry <me@claw0ry.net> | 2024-12-11 13:56:52 +0100 |
commit | 4719cc03837490ed4bf1b9725d75a686e56e5a6a (patch) | |
tree | 769dd3a3a87153df049b3043196bd131495b10ad /content/posts/copy-to-clipboard-in-servicenow.md |
fresh start
Diffstat (limited to 'content/posts/copy-to-clipboard-in-servicenow.md')
-rw-r--r-- | content/posts/copy-to-clipboard-in-servicenow.md | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/content/posts/copy-to-clipboard-in-servicenow.md b/content/posts/copy-to-clipboard-in-servicenow.md new file mode 100644 index 0000000..2937d9f --- /dev/null +++ b/content/posts/copy-to-clipboard-in-servicenow.md @@ -0,0 +1,25 @@ +--- +title: "Copy to Clipboard in Servicenow" +description: "A simple snippet for copying fields or other values to clipboard from a UI Action in ServiceNow" +tags: ["ServiceNow", "Javascript"] +date: 2024-03-22T14:10:35+01:00 +draft: false +--- + +Recently I was asked to find a way for users to easily create a string consisting of the task number and short description that they could paste into the time management software. In this short article we're going to take a look at how we can copy something to your system clipboard from a UI Action in ServiceNow. + +<!--more--> + +## The snippet + +```javascript +if (navigator.clipboard.writeText) { + var number = g_form.getValue('number'); + var short_description = g_form.getValue('short_description'); + navigator.clipboard.writeText(number + " - " + short_description).then(function() { + console.log("Copied!"); + }); +} +``` + +The `if` condition check wether your browser supports this function. Then we retrieve the value of fields `number` and `short_description` using `g_form`. Lastly we asynchronously write the the string to system clipboard. The `navigator.clipboard.writeText` is a native Javascript function and can be used on other sites aswell. |