From 4719cc03837490ed4bf1b9725d75a686e56e5a6a Mon Sep 17 00:00:00 2001 From: claw0ry Date: Wed, 11 Dec 2024 13:56:52 +0100 Subject: fresh start --- content/posts/copy-to-clipboard-in-servicenow.md | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 content/posts/copy-to-clipboard-in-servicenow.md (limited to 'content/posts/copy-to-clipboard-in-servicenow.md') 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. + + + +## 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. -- cgit v1.2.3