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

get status of cross references

New Here ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

Hi all

 

Is there a way to get the status of a cross reference in JavaScript, basically like LinkStatus.LINK_MISSING etc. but for cross references? I would like to loop through a book and report cross references with errors (missing document, missing source etc.) to the user.

TOPICS
Scripting

Views

135

Translate

Translate

Report

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 ,
Jun 17, 2024 Jun 17, 2024

Copy link to clipboard

Copied

Not really. Cross-references are underlyingly huperlinks whose source is a CrossRefereceSource. So you'd have to check those hyperlinks (they're not visible in the Hyperlinks panel).

 

If the cross-ref's source is deleted, the hyperlink is deleted as well.

If the cross-ref's destination is deleted, then the hyperlink's destination is null.

 

That's about all you can determine as far as I know.

 

P.

Votes

Translate

Translate

Report

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
New Here ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

Hi Peter

 

That's disappointing. Anyway, what I tried to do was finding hyperlinks with source CrossReferenceSource and destination null, like so:

var _currDoc = app.activeDocument;
var _errorHyperlinksDoc = [];
for (var i = 0; i < _currDoc.hyperlinks.length; i++) {
    var _hyperlink = _currDoc.hyperlinks[i];
      if (_hyperlink.source == "[object CrossReferenceSource]" && _hyperlink.destination == null) {
        _currDoc.hyperlinks[i].showSource();
        _errorHyperlinksDoc.push(app.selection[0].parentTextFrames[0].parentPage.name)
    }  
}
alert(_errorHyperlinksDoc);

 

However, even though one of my two cross references is kind of broken (it's not red with a question mark but a red flag with a question mark, so the destination has been deleted and should therefore be null (?)), the alert at the end returns empty. So, is there a way to achieve what I'm trying to do at all?

Votes

Translate

Translate

Report

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 ,
Jun 18, 2024 Jun 18, 2024

Copy link to clipboard

Copied

LATEST

Your script works fine over here, not sure why it doesn't work at your end. Maybe you could post the file.

 

Your script can be made more efficient as follows. Functionally it's the same as your script, it's just more efficient:

 

 

var _currDoc = app.activeDocument;
var _errorHyperlinksDoc = [];
var hlinks = _currDoc.hyperlinks.everyItem().getElements();
for (var i = 0; i < hlinks.length; i++) {
  var _hyperlink = hlinks[i];
  if (_hyperlink.source instanceof CrossReferenceSource 
      && _hyperlink.destination == null) {
    _errorHyperlinksDoc.push (
      _hyperlink.source.sourceText.parentTextFrames[0].parentPage.name
    );
  }
}
alert(_errorHyperlinksDoc);

 

Votes

Translate

Translate

Report

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