How to clean url parameters of a bookmark with smart rule?

I’m trying to clear the url parameters using a javascript code in a smart rule, but without success.

The idea would be to eliminate everything that comes after the ? in a URL, including the ? .

This is the javascript code I’m using within the action “Apply Script - Javascript”:

function performsmartrule(records) {
	var app = Application("DEVONthink 3");
	app.includeStandardAdditions = true;

	records.forEach (r => {
		const URL = r.url();
		const cleanUrl = URL.match(/([^\?]*).*$/);
		 if (result !== null) {
			r.url = cleanUrl;
		 }
	})
}

An example of a URL to be cleaned:
mywebsite.com/sale?utm_campaign=20_off&utm_medium=paid&utm_source=instagram&utm_content=bio

Desired result:
mywebsite.com/sale

Nothing happens to the bookmark url when I trigger the smart rule

match does not return a string in your case, since you’re using a capturing group (unnecessarily, btw). Check the documentation of the method at MDN.
Also, * matches 0 or more occurrences of the preceding expression. But you don’t want zero, so you must use another quantifier.

Something like
r.url = r.url().replace(/\?.*/,"")
should do the trick.

1 Like

Thank you!