Skip to main content
Nov 1, 2022 11:31 AM UTC
Solved

Windchill customization, copy checkin comment to clipboard

Hi there,

 

the default behavior of windchill is, that if somethings goes wrong during checkin process, the checkin comment is lost.

So I tweaked  <Windchill-installation>\codebase\templates\uwgm\cadx\checkin\checkintables.js a little to make a copy of the comment to a new window like:

 

var comment_window = window.open();
comment_window.document.writeln(comment);

(I intentionally left all code out, which "prettifies" the new window)

  works great!

 

Now I want to copy the comment directly to the clipboard.

But when I try this

// copy comment to clipboard

		navigator.clipboard.writeText(comment)
		.then(() => {
		 alert("successfully copied: " + comment);
		 })
		 .catch(() => {
			alert("something went wrong");
		 });

 I get the error under Creo 8.0.6.0, "checkintables.js Uncaught TypeError: Cannot read properties of undefined (reading 'then')"

 

What am I doing wrong?

MatAnswer
Nov 1, 2022 12:33 PM UTC

Ok, I think I found the solution

 

There is an article at w3docs.com about that.

https://www.w3docs.com/snippets/javascript/how-to-copy-the-text-to-the-clipboard-with-javascript.html

 

The third and last method works within Creo's embedded browser.

 

...
copyTextToClipboard(comment);
...
}

async function copyTextToClipboard(text) {
	try {
	 await navigator.clipboard.writeText(text);
	 console.log("Text copied to clipboard " + text);
	} catch(err) {
	 console.log('Error in copying text: ', err);
	}
 }

1 reply

MatAuthorAnswer
Nov 1, 2022 12:33 PM UTC

Ok, I think I found the solution

 

There is an article at w3docs.com about that.

https://www.w3docs.com/snippets/javascript/how-to-copy-the-text-to-the-clipboard-with-javascript.html

 

The third and last method works within Creo's embedded browser.

 

...
copyTextToClipboard(comment);
...
}

async function copyTextToClipboard(text) {
	try {
	 await navigator.clipboard.writeText(text);
	 console.log("Text copied to clipboard " + text);
	} catch(err) {
	 console.log('Error in copying text: ', err);
	}
 }