Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

InDesign Script Error

Community Beginner ,
Nov 17, 2022 Nov 17, 2022

Im trying to run a script which changes all of the hyperlinks in an Indesign file to include UTM tracking codes however Im getting an error on line 3 - wondering if anyone can help??

 

The code adds UTM tracking but also uses an if/then to check if there are more than one & in the code.  If there is more than one it adds a slightly different bit of text to the hyperlink.

 

When I run this in InDesign I get an error I have shown attached as a screenshot.

 

Here is my code and error message - I believe the error is on the line shown in red?

 

var utm = "utm_source=publications&utm_medium=sale-finder&utm_campaign=12-days-of-xmas";

var hlds = app.activeDocument.hyperlinkURLDestinations;
var utmsearch = "&" + utm;
var utmdefault = "?" + utm;

for (var i = 0; i < hlds.length; i++) {
var result = hlds.item(i).destinationURL.includes("?");
if (result) {
hlds.item(i).destinationURL += utmsearch;
} else {
hlds.item(i).destinationURL += utmdefault;
}
}

 

InDesign Error.pngexpand image

227
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2022 Nov 18, 2022

You've posted in the Muse community which is End of Life web design software. 

I'll move your post to InDesign where it belongs.

 

 

Nancy O'Shea— Product User, Community Expert & Moderator
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 18, 2022 Nov 18, 2022
LATEST

Hi @richardm74103734,

The issue is with the use of "includes" method as shown in the error message. InDesign scripting is based on ECMAScript 3 and it does not have many features and methods that the modern JS supports and "includes" method is one such missing method. You can look at the methods supported by string object via the following link

https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#String.html

For your use case you could either use the match method with a regex as an argument, or if you are seraching for ? as the last character of the string then you can just check last character and use the simple comparison. You could also check the test method of RegExp class

https://www.indesignjs.de/extendscriptAPI/indesign-latest/index.html#RegExp.html#d1e5861__d1e6198

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines