Skip to main content
Inspiring
April 8, 2022
Question

Using a script to data Merge, but getting an error about about a dialog being open. Error Code#30486

  • April 8, 2022
  • 1 reply
  • 198 views

I'm very new to scripting and working on the first step of a script, but i keep getting back an error stating 

Error Code# 30486: Cannot handle the request because a modal dialog or alert is active. @ file '~/Library/Preferences/Adobe%20InDesign/Version%2017.0/en_US/Scripts/Scripts%20Panel/Glossary%20Terms%20Test.jsx' [line:43, col:NaN]

its happening at the line 

    doc.dataMergeProperties.selectDataSource(dataSource);

Here the full code

var doc = app.activeDocument;
var dataSource;


// DIALOG
// ======
var dialog = new Window("dialog"); 
    dialog.text = "Import Glossary List"; 
    dialog.orientation = "column"; 
    dialog.alignChildren = ["center","top"]; 
    dialog.spacing = 10; 
    dialog.margins = 16; 




// IMPORT LIST BUTTON    
var button1 = dialog.add("button", undefined, undefined, {name: "button1"}); 
button1.text = "Import Glossary List"; 


button1.addEventListener("click", selectFile);
// button1.addEventListener("click", dataMerge);

// app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;

function selectFile(){
    // doc.dataMergeProperties.selectDataSource(File.openDialog("Choose a Tabbed Dilimited .txt File", filterFiles, false));
    
    // Not sure what this does but it prevented errors
    // exit();
    
    // Didn't work
    // File(dataSource);
    dialog.close();
    dataSource = File.openDialog("Choose a Tabbed Dilimited .txt File", filterFiles, false);
    doc.dataMergeProperties.selectDataSource(dataSource);

    
    if (dataSource != null){
        $.writeln(dataSource.fullName);

        // dataSource.close();

        // dataMerge();

        // return dataSource.fullName;
        // doc.dataMergeProperties.selectDataSource(File);
    }
    else{
        $.writeln("NULL");
        // return null;
    }
    // $.writeln("hello");
}

function dataMerge(){
    $.writeln("Hi");
    // dialog.close()
    doc.dataMergeProperties.selectDataSource(dataSource);
}

function filterFiles(file){
    if (file.name.match(/\.txt$/))
    {
        return true;
    }

    return false;
}

// button1.onCLick = doc.dataMergeProperties.selectDataSource(File.openDialog("Choose a Tabbed Dilimited .txt File"));

    //Display a standard Open File dialog box.
    
    // var dataSource = File.openDialog("Choose a Tabbed Dilimited .txt File");

        // var dataSource = File.openDialog("Choose a Tabbed Dilimited .txt File");

        // file = File.openDialog("Choose a Tabbed Dilimited .txt File");
        // doc.dataMergeProperties.selectDataSource(dataSource);


        

// GROUP1
// ======
// var group1 = dialog.add("group", undefined, {name: "group1"}); 
//     group1.orientation = "row"; 
//     group1.alignChildren = ["left","center"]; 
//     group1.spacing = 10; 
//     group1.margins = 0; 

// var statictext1 = group1.add("statictext", undefined, undefined, {name: "statictext1"}); 
//     statictext1.text = "Select Glossary Column"; 

// var dropdown1_array = ["Item 1","-","Item 2"]; 
// var dropdown1 = group1.add("dropdownlist", undefined, undefined, {name: "dropdown1", items: dropdown1_array}); 
//     dropdown1.selection = 0; 

// // GROUP2
// // ======
// var group2 = dialog.add("group", undefined, {name: "group2"}); 
//     group2.orientation = "row"; 
//     group2.alignChildren = ["left","center"]; 
//     group2.spacing = 10; 
//     group2.margins = 0; 

// var statictext2 = group2.add("statictext", undefined, undefined, {name: "statictext2"}); 
//     statictext2.text = "Select Definition Column"; 

// var dropdown2_array = ["Item 1","-","Item 2"]; 
// var dropdown2 = group2.add("dropdownlist", undefined, undefined, {name: "dropdown2", items: dropdown2_array}); 
//     dropdown2.selection = 0; 

// // GROUP3
// // ======
// var group3 = dialog.add("group", undefined, {name: "group3"}); 
//     group3.orientation = "row"; 
//     group3.alignChildren = ["left","center"]; 
//     group3.spacing = 10; 
//     group3.margins = 0; 

// var statictext3 = group3.add("statictext", undefined, undefined, {name: "statictext3"}); 
//     statictext3.text = "Specify First Row"; 

// var edittext1 = group3.add('edittext {properties: {name: "edittext1"}}'); 
//     edittext1.preferredSize.width = 40; 

// DIALOG
// ======
var Generate = dialog.add("button", undefined, undefined, {name: "Generate"}); 
    Generate.text = "Generate Glossary"; 

    Generate.onClick = function () {
    dataMerge();
}

var divider1 = dialog.add("panel", undefined, undefined, {name: "divider1"}); 
    divider1.alignment = "fill"; 

var CloseButton = dialog.add("button", undefined, undefined, {name: "CloseButton"}); 
    CloseButton.text = "Close"; 

    CloseButton.onClick = function () {
    dialog.close(2);
}

dialog.show();

 and yet this simple code does work

var doc = app.activeDocument;
doc.dataMergeProperties.selectDataSource(File.openDialog("Choose a Tabbed Dilimited .txt File"));

its only when its tied to a button that it won't work, what am i doing wrong?

This topic has been closed for replies.

1 reply

Legend
April 9, 2022

Hello @SweatersInSummer,

 

Your code is a bit convoluted and is not the approach I would have taken,  I don't time to give you more of an explanation right now, but if you move the line(s) of code that's giving you the error to the end it works,

dialog.show();

dataSource = File.openDialog("Choose a Tabbed Dilimited .txt File", filterFiles, false);
doc.dataMergeProperties.selectDataSource(dataSource);

 

Regards,

Mike