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

How to loop through multiple shared Hyperlink destinations and turn off "sharing"

Guest
Dec 07, 2016 Dec 07, 2016

Copy link to clipboard

Copied

Hi there,

I've been using this other forum post as a guide : Shared Hyperlink Destination (thread/791822) but unfortunately I can't quite get the behaviour i need.

Essentially I have documents that contain lots of shared destination URL hyperlinks. So there are multiple shared destinations and there are multiple hyperlinks using each shared destination.

I need to give each hyperlink their own destination URL and remove all shared urls. This then allows me to loop through all the hyperlinks and individually adjust their destination URL based on some other criteria (which I do later in the script).

My understanding is that to remove shared destinations I need to change the "hidden" property from "false" to "true" for shared destinations. It also seems that the only way to do this is to delete and recreate the hyperlink URL destination.

The problem with my current approach is that it removes the shared destination correctly, but it only adds an unshared location back to one of the hyperlinks that was using that shared destination. All the other hyperlinks that were using that shared destination now have NO destination value.

This has been my approach :

  1. Loop through all hyperlinks that contain a HyperlinkURLDestination and have the destination.hidden value set to 'false'
  2. For the current hyperlink, capture the destinationURL into a variable.
  3. Now remove the destination from that hyperlink.
  4. Add a new destination URL to the current hyperlink using the value stored in the variable (which is the same as what it was originally) and set 'hidden' to true (so destination is not shared).

The above works perfectly for the current hyperlink, but all other hyperlinks that used that shared Destination URL now have no value.

To solve the problem I'm thinking the following approach might work but I'm having trouble working out the correct code:

  1. Instead of looping through hyperlinks, loop through hyperlinkURLDestinations (whose hidden value is set to 'false')
  2. For the current hyperlinkURLDestination, capture the destinationURL into a variable
  3. Now get a 'list' of all the hyperlinks that use the current hyperlinkURLDestination
  4. Delete the hyperlinkURLDestination
  5. Loop thru each hyperlink in the list created at step 3 and add a new destination URL to the current hyperlink using the value stored in the variable (which is the same as what it was originally) and set 'hidden' to true (so destinations aren't shared).
  6. Now proceed to next hyperlinkURLDestination and repeat steps

My key problem is I don't know what javascript I need to write to for Step 3 - how do I get that list of hyperlinks that use the current hyperlinkURLDestination??? Any help to work out how to do that (or any suggestions on a better approach) would be greatly appreciated!

Many thanks, HJ

TOPICS
Scripting

Views

1.8K

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

correct answers 1 Correct answer

Deleted User
Dec 13, 2016 Dec 13, 2016

Thanks Pickory - I'll probably use this code for another issue. As for this issue I ended up going with this solution:

1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label

2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations

3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.

Its probably not the fastest option in terms of performa

...

Votes

Translate

Translate
Guest
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

Here is another idea that I might try:

1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label

2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations

3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.

HJ

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
Guide ,
Dec 08, 2016 Dec 08, 2016

Copy link to clipboard

Copied

Hello,

Here is a lump of code I use to build a list of destinations and source.

//===================

  var hypers = app.documents[0].hyperlinks.everyItem().getElements();

  

  for ( len = 0; len < hypers.length; len++ )

  {

  // ===== START destinationURL

  try

  {

  if (( hypers[len].destination ) && ( hypers[len].destination.hasOwnProperty("destinationURL")) && (hypers[len].destination.destinationURL.length ))

  {

  if ( hypers[len].source instanceof HyperlinkPageItemSource )

  continue;

  if ( 'undefined'==typeof hypers[len].source )

  continue;

  if ( 'undefined'==typeof hypers[len].source.sourceText )

  continue;

  if ( 'undefined'==typeof hypers[len].source.sourceText.parentTextFrames[0] )

  continue;

  if ( hypers[len].source.sourceText.contents.length )

  {

  hyperDesinations[nn] = {};

  hyperDesinations[nn]["PARENT"] = hypers[len].source.sourceText.parentTextFrames[0];

  hyperDesinations[nn]["id"] = hypers[len].source.sourceText.parentTextFrames[0].id;

  hyperDesinations[nn]["TYPE"] = "URLDest";

  hyperDesinations[nn]["SRC"] = hypers[len].source;

  hyperDesinations[nn]["DEST"] = hypers[len].destination.destinationURL;

  hyperDesinations[nn]["PARA"] = "";

  nn++;

                    continue;

  }

  }

  }

  catch ( e ) {;}

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
Guest
Dec 13, 2016 Dec 13, 2016

Copy link to clipboard

Copied

Thanks Pickory - I'll probably use this code for another issue. As for this issue I ended up going with this solution:

1. Loop thru all hyperlinks and put a copy of the URLdestination text into the hyperlink label

2. Once all hyperlinks have been looped thru, delete all shared hyperlink URLdestinations

3. Now loop back thru hyperlinks again and take the value in the label and use it to re create the hyperlink URLdestination for that hyperlink.

Its probably not the fastest option in terms of performance but it was very easy to script : )

Here is an extract from my script for the above steps:

var myDoc=app.documents[0]

var myLinks=myDoc.hyperlinks.everyItem().getElements()

var myLinkDestinations = myDoc.hyperlinkURLDestinations.everyItem().getElements()

var myShareStatus

var myDestName = "www.xx.com"

var myDest

// 1. Loop thru all hyperlinks and put copy of the URL destination text in hyperlink label.

// Do only for hyperlinks that : (a) have a destination  (b) is of destination type 'HyperlinkURLDestination' 

// (c) the destination link contains 'www.xx.com' and (d) the destination link is shared

for(var i = myLinks.length-1; i>=0; i--)

    {

// Have 'try' statement to bypass links that are broken/don't have a destination

try{

myShareStatus = myLinks.destination.hidden

if (myLinks.destination instanceof HyperlinkURLDestination && myShareStatus = "false" ){

if (myLinks.destination.destinationURL.indexOf('www.xx.com') >= 0){

   

// 2. If the hyperlink is shared, the hyperlink URL destination value needs to be added to the hyperlink label

    if (myShareStatus = "false"){

       myDest = myLinks.destination.destinationURL 

       myLinks.label  = myDest

}

}

}

}

catch (err) {

   //Do nothing

}

}

// 3. Loop thru hyperlink URLdestinations and delete any that are shared

for(var e = myLinkDestinations.length-1; e>=0; e--)

    {

myShareStatus = myLinkDestinations.hidden

if (myLinkDestinations.destinationURL.indexOf('www.xx.com') >= 0 && myShareStatus = "false"){

   myLinkDestinations.remove();

   }

}

// 4. Loop thru hyperlinks and recreate hyperlink URLDestination from value in 'label' field.

//Only recreate URLDestination from 'label'  if value in 'label' field contains www.xx.com

for(var i = myLinks.length-1; i>=0; i--)

    {

if (myLinks.label.indexOf('www.xx.com') >= 0){

    myDest = myLinks.label

    myCounter = myCounter + 1

    myDestName =  myDestName + String(myCounter)   

var myNewDest = myDoc.hyperlinkURLDestinations.add( myDest, {name:myDestName, hidden: true} );

       myLinks.destination = myNewDest;

}

}

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 Beginner ,
Feb 08, 2019 Feb 08, 2019

Copy link to clipboard

Copied

LATEST

This should help some people:

1- Open HYPERLINKS window

2- Select all the hyperlinks you would like to UNCHECK their shared destination.

3- Double click on one of the hyperlinks you selected

4- When prompted, UNCHECK the shared destination box.

It will UNCHECK all that are selected.

Hope that helps.

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