These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Broken Script: Broken text field link & change date format

Hoyane
Registered: Nov 26 2011
Posts: 33
Answered

Ok so I had this stamp complete and just had to add a "auto date fill" to the script. I tried merging the sample script into my own but could never get it right. So I merged my script into the sample and it worked mostly. Somehow i managed to break one of the text field links. The five lines of code below are the only things i couldnt merge. Actually the first three i couldnt get in the script due to syntax errors. I moved all the code to a text field that is static because thats the only way i could get it to work without the 3 lines( I replaced it with a getField function).
The last two i got in the script but that field did not function at all. So my first three fields work properly, datebilled does not.
Lastly, the date being returned is not what i want. I thought i changed it with this line
AFDate_FormatEx("mm/dd/yyyy");
but it did not work.
It returns: Thu Dec 01 2011 20:09:07 GMT-0600 (Central Standard Time)
I want: 12/01/2011
 
So there are two things i need help with. getting "datebilled" to work again and change the date format. Everything else in the script works.
   
var cMsg = dialog.Date;
event.value = "\n" + cMsg;
event.source.source.info.exhibit = cMsg;
 
cMsg = "\n" + dialog.datebilled;
this.getField("datebilled").value = cMsg;
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
This is what i have:
   
// Dialog Definition
var Dialog = {
// This dialog box is called when the dialog box is created
strName: "",
initialize: function(dialog)
{
this.loadDefaults(dialog);
dialog.load({"usnm":this.strName});
},
commit: function(dialog)
{
var results = dialog.store();

testValue = results["txt2"];
testValue2 = results["txt3"];
this.datebilled = results["txt4"];
var data = dialog.store();
this.strName = data["usnm"];
var elements = dialog.store()["txt2"];
for(var i in elements) {
if ( elements[i] > 0 ) {
testValue = elements[i];
}
}
},
loadDefaults: function (dialog) {
dialog.load({
txt2:
{
"*Not Specified": +1,
"Donations": -2,
"Office Supplies": -3,
"Outsourced Services": -4,
"Paper": -5,
"Telecommunications": -6,
"Utilities": -7
}
})
},
description:
{
name: "eBook Creation",
elements:
[
{
type: "view",
elements:
[
 
{
name: "Date:",
type: "static_text",
},
{
item_id: "usnm",
type: "edit_text",
width: 120
},
{
name: "GL Code: ",
type: "static_text",
},
{
item_id: "txt2",
type: "popup",
width: 120,
},
{
name: "Outsourced: ",
type: "static_text",
},
{
type: "radio",
item_id: "txt3",
name: "No",
group_id: "g1",
width: 120,
height: 25
},
{
type: "radio",
item_id: "txt3",
name: "Yes",
group_id: "g1",
width: 120,
height: 25
},
{
name: "Invoice # Billed On: ",
type: "static_text",
},
{
item_id: "txt4",
type: "edit_text",
multiline: false,
width: 120,
height: 20
},
{
type: "ok_cancel",
},
]
},
]
}
};
 
if(event.source.forReal && (event.source.stampName == "#Billing"))
{
Dialog.strName = (new Date()).toString();
AFDate_FormatEx("mm/dd/yyyy");
if ("ok" == app.execDialog(Dialog))
{
this.getField("usnm").value = Dialog.strName;
 
var textValue;
if (testValue==1) textValue = "Not Specified";
else if (testValue==2) textValue = "Donations";
else if (testValue==3) textValue = "Office Supplies";
else if (testValue==4) textValue = "Outsourced Services";
else if (testValue==5) textValue = "Paper";
else if (testValue==6) textValue = "Telecommunications";
else if (testValue==7) textValue = "Utilities";
 
this.getField("GLCode").value = textValue;
 
var textValue2;
if (testValue2==true) textValue2 = "Yes";
else if (testValue2==false) textValue2 = "No";
this.getField("Outsourced").value = textValue2;
  
}
}

My Product Information:
Acrobat Pro 10.1, Windows
Hoyane
Registered: Nov 26 2011
Posts: 33
Accepted Answer
So i figured out the date part. Here is the change for anyone looking.

Dialog.strName = (new Date()).toString();
AFDate_FormatEx("mm/dd/yyyy");

and replaced with

Dialog.strName = util.printd("mm/dd/yyyy",new Date());


I am still stuck trying to make my last field work again. I can place the code without syntax errors but it still doesnt work.


var textValue2;
if (testValue2==true) textValue2 = "Yes";
else if (testValue2==false) textValue2 = "No";
else if (testValue2==off) textValue2 = "Not Specified";
this.getField("Outsourced").value = textValue2;

Please help!


XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

UPDATE:

So i had what i think is progress. I couldn't get any response using the cMsg = so I tried calling the dialog the same way as the popup and radio using var textValue3 and am getting back an undefined error, which i think is good as its getting input.
With help from try67 i learned how to convert the values returned to text for the popup and radio. Problem is in applying that idea to this field, this is not a static value being returned. It is a edit_text box with an invoice number being inputted. So i cant apply the convert part to this field as it needs to be what was put in the box. Not sure if i need to go back to using the cMsg = method, but i couldnt get that either.

I am also still trying to figure out the no radio selection returning "No" instead of "not selected".

At this point i don't think i can fix this. I have scoured the forum trying to find a related script to no avail. I am pretty sure this is the final draft of this stamp and just need that last two parts fixed. So close i can taste it!

Here is what i have with the "undefined" result, but again, not sure if i need to go back to cMsg = which is the one in first post.

// Dialog Definition
var Dialog = {
// This dialog box is called when the dialog box is created
strName: "",
initialize: function(dialog)
{
this.loadDefaults(dialog);
dialog.load({"usnm":this.strName});
},
commit: function(dialog)
{
var results = dialog.store();
testValue = results["txt2"];
testValue2 = results["txt3"];
this.datebilled = results["txt4"];
var data = dialog.store();
this.strName = data["usnm"];
var elements = dialog.store()["txt2"];
for(var i in elements) {
if ( elements[i] > 0 ) {
testValue = elements[i];
}
}
},
loadDefaults: function (dialog) {
dialog.load({
txt2:
{
"*Not Specified": +1,
"Donations": -2,
"Office Supplies": -3,
"Outsourced Services": -4,
"Paper": -5,
"Telecommunications": -6,
"Utilities": -7
}
})
},
description:
{
name: "eBook Creation",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
width: 142,
height: 28,
char_height: 10,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "stat",
name: "Date:",
width: 35,
height: 18,
char_width: 15,
alignment: "align_top",
font: "dialog",
},
{
type: "edit_text",
item_id: "usnm",
char_width: 8,
},
]
},
{
type: "view",
width: 214,
height: 48,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta1",
name: "GL Code:",
width: 55,
height: 17,
alignment: "align_top",
},
{
type: "popup",
item_id: "txt2",
width: 115,
height: 23,
char_width: 8,
},
]
},
{
type: "view",
width: 174,
height: 48,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta1",
name: "Outsourced:",
width: 70,
height: 16,
alignment: "align_left",
},
{
type: "radio",
item_id: "txt3",
group_id: "GRP1",
name: "Yes",
},
{
type: "radio",
item_id: "txt3",
group_id: "GRP1",
name: "No",
width: 48,
height: 23,
},
]
},
{
type: "gap",
item_id: "gap2",
width: 149,
height: 3,
char_width: 4,
char_height: 4,
},
{
type: "view",
width: 214,
height: 5,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta2",
name: "Invoice # Billed On:",
width: 110,
height: 16,
},
{
type: "edit_text",
item_id: "txt4",
char_width: 8,
},
]
},
{
type: "gap",
item_id: "gap1",
width: 149,
height: 3,
char_width: 4,
char_height: 4,
},
{
type: "view",
width: 100,
height: 43,
char_width: 8,
char_height: 8,
align_children: "align_center",
alignment: "align_center",
elements:
[
{
type: "ok_cancel",
},
]
},
]
},
]
}
};

if(event.source.forReal && (event.source.stampName == "#Billing"))
{
Dialog.strName = util.printd("mm/dd/yyyy",new Date());


if ("ok" == app.execDialog(Dialog))
{

this.getField("usnm").value = Dialog.strName;

var textValue3;
this.getField("datebilled").value = textValue3;

var textValue;
if (testValue==1) textValue = "Not Specified";
else if (testValue==2) textValue = "Donations";
else if (testValue==3) textValue = "Office Supplies";
else if (testValue==4) textValue = "Outsourced Services";
else if (testValue==5) textValue = "Paper";
else if (testValue==6) textValue = "Telecommunications";
else if (testValue==7) textValue = "Utilities";

this.getField("GLCode").value = textValue;

this.getField("Outsourced").value = "";

var textValue2;
if (testValue2==true) textValue2 = "Yes";
else if (testValue2==false) textValue2 = "No";
else if (testValue2==off) textValue2 = "Not Selected";
this.getField("Outsourced").value = textValue2;

}
}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Update2:

I've gotten the entire script working. It seems if i keep trying I get it eventually. Very hard though. Must have made 200+ attempts piecing together different scripts. I hope that this saves someone a bunch of headaches as this script for a dynamic document stamp does a lot of different things.

Thanks to try67 for helping me get the popup list variables converted to text.

Here is the final script:



// Dialog Definition
var Dialog = {
// This dialog box is called when the dialog box is created
strName: "",
strName2: "",
initialize: function(dialog)
{
this.loadDefaults(dialog);
dialog.load({"date":this.strName});

},
commit: function(dialog)
{
var results = dialog.store();
testValue = results["txt2"];
testValue2 = results["txt3"];
this.datebilled = results["txt4"];
var data = dialog.store();
this.strName2 = data["txt4"];
this.strName = data["date"];
var elements = dialog.store()["txt2"];
for(var i in elements) {
if ( elements[i] > 0 ) {
testValue = elements[i];
}
}
},
loadDefaults: function (dialog) {
dialog.load({
txt2:
{
"*Not Specified": +1,
"Donations": -2,
"Office Supplies": -3,
"Outsourced Services": -4,
"Paper": -5,
"Telecommunications": -6,
"Utilities": -7
}
})
},
description:
{
name: "eBook Creation",
elements:
[
{
type: "view",
elements:
[
{
type: "view",
width: 142,
height: 28,
char_height: 10,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "stat",
name: "Date:",
width: 35,
height: 18,
char_width: 15,
alignment: "align_top",
font: "dialog",
},
{
type: "edit_text",
item_id: "date",
char_width: 8,
},
]
},
{
type: "view",
width: 214,
height: 48,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta1",
name: "GL Code:",
width: 55,
height: 17,
alignment: "align_top",
},
{
type: "popup",
item_id: "txt2",
width: 115,
height: 23,
char_width: 8,
},
]
},
{
type: "view",
width: 174,
height: 48,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta1",
name: "Outsourced:",
width: 70,
height: 16,
alignment: "align_left",
},
{
type: "radio",
item_id: "txt3",
group_id: "GRP1",
name: "Yes",
},
{
type: "radio",
item_id: "txt3",
group_id: "GRP1",
name: "No",
width: 48,
height: 23,
},
]
},
{
type: "gap",
item_id: "gap2",
width: 149,
height: 3,
char_width: 4,
char_height: 4,
},
{
type: "view",
width: 214,
height: 5,
char_width: 8,
char_height: 8,
align_children: "align_row",
alignment: "align_left",
elements:
[
{
type: "static_text",
item_id: "sta2",
name: "Invoice # Billed On:",
width: 110,
height: 16,
},
{
type: "edit_text",
item_id: "txt4",
char_width: 8,
},
]
},
{
type: "gap",
item_id: "gap1",
width: 149,
height: 3,
char_width: 4,
char_height: 4,
},
{
type: "view",
width: 100,
height: 43,
char_width: 8,
char_height: 8,
align_children: "align_center",
alignment: "align_center",
elements:
[
{
type: "ok_cancel",
},
]
},
]
},
]
}
};

if(event.source.forReal && (event.source.stampName == "#Billing"))
{
Dialog.strName = util.printd("mm/dd/yyyy",new Date());


if ("ok" == app.execDialog(Dialog))
{

this.getField("date").value = Dialog.strName;

var textValue;
if (testValue==1) textValue = "Not Specified";
else if (testValue==2) textValue = "Donations";
else if (testValue==3) textValue = "Office Supplies";
else if (testValue==4) textValue = "Outsourced Services";
else if (testValue==5) textValue = "Paper";
else if (testValue==6) textValue = "Telecommunications";
else if (testValue==7) textValue = "Utilities";
this.getField("GLCode").value = textValue;

var textValue2;
if (testValue2==false) textValue2 = "Yes";
else if (testValue2==true) textValue2 = "No";
this.getField("Outsourced").value = textValue2;

this.getField("datebilled").value = Dialog.strName2;

}
}