Skip to main content
dublove
Legend
Jun 6, 2025 4:49 AM UTC
Answered

How do I get a dialog box to pop up so I can choose whether to execute a certain piece of code?

Specific:

I want the program to pop up a dialog box so that I can choose whether I want to skip table headers or not.

myTable.breakHeaders = HeaderFooterBreakTypes.IN_ALL_TEXT_COLUMNS;
myTable.skipFirstHeader = true;

Also I want to choose whether to execute a certain piece of code or not, for example:

var myFooterRow = myTable.rows[-1];

function dupeLastRow(p){
	myTable.rows.add(LocationOptions.AFTER, myTable.rows[-1]);
	myFooterRow = myTable.rows[-1];
}
dupeLastRow(myTable);
...
...

Thank you~

rob day
rob dayCorrect answer
Community Expert
Jun 6, 2025 3:47 PM UTC

Hi @dublove , There are two ways to make dialogs with the JS API I prefer this one:

 

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

 

There’s also the Window class but it think it is harder to learn

 

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

 

Here is a simple checkbox example:

 

 

 

//the checkbox result variable
var ck  
makeDialog();

/**
* Make the  dialog 
*/
function makeDialog(){
    var d = app.dialogs.add({name:"Table Headers", canCancel:true});
    with(d){
        with(dialogColumns.add()){
            staticTexts.add({staticLabel:"Skip Headers:"});
        }
        with(dialogColumns.add()){
            ck = checkboxControls.add({checkedState:false, minWidth:150});
        }
    }
    if(d.show()){
        //get the result
        ck = ck.checkedState;
        main()
	}else{
        d.destroy();
    }
}


/**
* The Script to run after getting dialog result
* @ return void 
*/

function main(){
    alert("Dialog Results\ncheck box= "+ ck)
}

3 replies

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
Jun 6, 2025 3:47 PM UTC

Hi @dublove , There are two ways to make dialogs with the JS API I prefer this one:

 

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

 

There’s also the Window class but it think it is harder to learn

 

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

 

Here is a simple checkbox example:

 

 

 

//the checkbox result variable
var ck  
makeDialog();

/**
* Make the  dialog 
*/
function makeDialog(){
    var d = app.dialogs.add({name:"Table Headers", canCancel:true});
    with(d){
        with(dialogColumns.add()){
            staticTexts.add({staticLabel:"Skip Headers:"});
        }
        with(dialogColumns.add()){
            ck = checkboxControls.add({checkedState:false, minWidth:150});
        }
    }
    if(d.show()){
        //get the result
        ck = ck.checkedState;
        main()
	}else{
        d.destroy();
    }
}


/**
* The Script to run after getting dialog result
* @ return void 
*/

function main(){
    alert("Dialog Results\ncheck box= "+ ck)
}
Translate
dublove
dubloveAuthor
Legend
Jun 6, 2025 4:05 PM UTC

Hi rob day

How does your dialog box hook up with my code?
How do I pass values to the code?

Translate
rob day
Community Expert
Community Expert
Jun 6, 2025 4:16 PM UTC

In my main function you can run an if statement to check and act on the result

 

function main(){
    //if the check box is checked
    if (ck) {
        alert("Skip First Head")
        //code to skip here

    } else (
        alert("Allow First Head")
        //code to allow here
    )
}
Translate