This is the main script code, located C: \ Program Files (x86) \ Adobe \ Acrobat DC \ Acrobat \ Javascripts
app.addMenuItem({ cParent:"Help", cName:"-", cExec:" ", nPos: 0});
app.addMenuItem({ cParent: "Help", cUser: "Test", cName: "Test", cExec: "Test()", cEnable: "event.rc = (event.target != null);", nPos: 0});
function Test()
{
var dialog1 =
{
Btn1: function(dialog)
{
var result = dialog.store()["Txt1"]
Ndata = result
dialog.end("Btn1");
},
Stop: function(dialog)
{
idx = "Cancel"
dialog.end("Stop");
},
description:
{name: "Test", align_children: "row", width: 300, height: 300,
elements:
[
{
alignment: "align_right",
type: "button",
name: "Cancel",
item_id: "Stop",
width: 5
},
{
type: "edit_text",
item_id: "Txt1",
width: 170,
height: 25
},
{
type: "button",
name: "Enter date",
item_id: "Btn1",
}
]
}
};
app.execDialog(dialog1);
array = this.getPageBox("Crop",1);
r = array.toString()
r = r.split(",");
rectX1 = [Math.round(r[2])-391, 108, Math.round(r[2])-354, 132];
this.addAnnot({page: 1, type: "Stamp", rect: rectX1, author: "", AP: "#NewDate" })
}; app.trustedFunction(Test);
Stamp template located C: \ Users \ 1 \ AppData \ Roaming \ Adobe \ Acrobat \ DC \ Stamps


You should add a definition for Ndata outside the scope of the dialog.
Add this as the first line of code:
var Ndad;