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

Javascript - Add pages, open doc, add pages

New Here ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

Quick background on what I'm trying to do. I have a bunch of files with similar file names.  Right now, I have an action wizard action running javascript that allows me to select the first file and my code will automatically insert the pages of all the other similarly named files in the correct order. So for example:

 

I select a file named 08252022 and hit run.

The files 08252022_A gets inserted, then 08252022_B, then 08252022_C, etc.

 

Since the files names have a normal convention this allows me to select all files in a folder, regardless of it being 1 or 100, and the proper files get inserted where they need to go.

 

Now I need to tweak it so it still does its main task but a separate file needs to get created at the end.  So for example:

 

Select 08252022

File 08252022_A gets inserted, then 08252022_E, then 08252022_F, then save

File 08252022_B automatically has 08252022_C and 08252022_D inserted into it and saved to a different location

 

My problem is that when I use the openDoc() function the "focus" is still on the first file. So inserting pages still insert them into 08252022. Not 08252022_B.  Is there a way to shift focus mid execution so the files get inserted where they need to go?  Or do I have to finish the action and start a new one?

 

Thanks!

TOPICS
JavaScript

Views

227

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

Community Expert , Aug 25, 2022 Aug 25, 2022

When you use openDoc it returns a Document object (if successful). That object is what you need to use later on when inserting new pages, instead of the "this" keyword. If you do that it won't matter which file has the focus.

However, you'll also need to save (and close) this file in your code when done with it, as the Action won't do that for you.

Votes

Translate

Translate
Community Expert ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

When you use openDoc it returns a Document object (if successful). That object is what you need to use later on when inserting new pages, instead of the "this" keyword. If you do that it won't matter which file has the focus.

However, you'll also need to save (and close) this file in your code when done with it, as the Action won't do that for you.

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 ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

Gosh I feel stupid for missing something so elementary. That is what I needed. Thank you!

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 ,
Aug 25, 2022 Aug 25, 2022

Copy link to clipboard

Copied

LATEST

Another option, maybe a better one, is to check the file-name first, then decide how to handle it.

If it ends with a number, process it like you described in the first part. If it ends with "_B", process it differently.

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