Skip to main content
Participant
November 18, 2022
Question

InDesign Script Error

  • November 18, 2022
  • 2 replies
  • 272 views

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;
}
}

 

    This topic has been closed for replies.

    2 replies

    Community Expert
    November 19, 2022

    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

    -Manan
    Nancy OShea
    Community Expert
    Community Expert
    November 19, 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