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

Please help finish this script

Hoyane
Registered: Nov 26 2011
Posts: 33
Answered

Hello , I was hoping someone could help me finish this code. Ive managed to piece this together from existing dynamic stamps and some API Javascript guide, but I have hit a dead end. Most everything is working but some final tweaks are needed.
 
1st the popup list result. I need the result from the popup list to be placed in a text field. Right now it reports the result in a java popup window, I tried to remove it but it seems to break the code.
 
2nd i would like to make the result returned from the radio buttons to be Yes and No instead of True False
 
Here is the code so far.
  
var dialog = {
exhibitValue: "",
caseValue: "",
// This dialog box is called when the dialog box is created
initialize: function(dialog) {
this.loadDefaults(dialog);
},
// This dialog box is called when the OK button is clicked.
 
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
this.Date = results["txt1"];
this.exhibitValue = results["txt2"];
this.datebilled = results["txt4"];
this.Outsourced = results["txt5"];
var elements = dialog.store()["subl"];
for(var i in elements) {
if ( elements[i] > 0 ) {
app.alert("You chose \"" + i
+ "\", which has a value of " + elements[i] );
}
}
},
loadDefaults: function (dialog) {
dialog.load({
subl:
{
"Acrobat Professional": +1,
"Acrobat Standard": -2,
"Adobe Reader": -3
}
})
},
 
description:
{
name: "VVVVVVVVVVVVVVVVVVV", // Dialog box title
elements: // Child element array
[
{
type: "view",
align_children: "align_left",
elements: // Child element array
[
{
name: "TEST: ",
type: "static_text",
font: "ariel"
},
{
item_id: "subl",
type: "popup",
width: 140,
},
{
name: "Date: ",
type: "static_text",
},
{
item_id: "txt1",
type: "edit_text",
multiline: true,
width: 168,
height: 20
},
{
name: "Outsourced: ",
type: "static_text",
},
{
type: "radio",
item_id: "txt5",
name: "No",
group_id: "g1",
width: 30,
height: 25
},
{
type: "radio",
item_id: "txt5",
name: "Yes",
group_id: "g1",
width: 30,
height: 25
},
{
name: "GL Code: ",
type: "static_text",
},
{
item_id: "txt2",
type: "edit_text",
multiline: true,
width: 168,
height: 20
},
{
name: "Date invoiced on: ",
type: "static_text",
},
{
item_id: "txt4",
type: "edit_text",
multiline: true,
width: 168,
height: 20
},
{
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel"
},
]
},
]
}
};
  
if(event.source.forReal && (event.source.stampName == "#caseandnumfill"))
{
if ("ok" == app.execDialog(dialog))
{
var cMsg = dialog.Date;
event.value = "Case:\n" + cMsg;
event.source.source.info.exhibit = cMsg;
 
cMsg = "GL Code:\n" + dialog.exhibitValue;
this.getField("ExhibitNumFieldF").value = cMsg;
 
cMsg = "Bill Date:\n" + dialog.datebilled;
this.getField("datebilled").value = cMsg;
 
cMsg = "Outsourced:\n" + dialog.Outsourced;
this.getField("Outsourced").value = cMsg;
 
cMsg = "subl:\n" + dialog.subl;
this.getField("subl").value = cMsg;
}
}

My Product Information:
Acrobat Pro 10.1, Windows
Hoyane
Registered: Nov 26 2011
Posts: 33
If anyone could point me to a working sample that would be very helpful also. I need one with a java popup window with a dropdown list selection with that result returned to a text field. Then one with a java popup window with a radio selection that returns a result other that true and false.
I have managed to break the dropdown result java popup but it would be nice to clean up that part of the code. I still cant get the result to go to the text field. It returns "undefined" result in text box.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
There are examples of the Dialog in the reference files. To use the values from the dialog outside of it you should define the variables to hold those values outside the dialog, and then set their values in the commit event.
Then you'll have access to them even after the dialog is closed.
So something like this:

var testValue;

var dialog = {

// dialog code...
commit:function (dialog) {
var results = dialog.store();
testValue = results["txt1"];
}
}



if (app.execDialog(dialog)=="ok") {
this.getField("test").value = testValue;
}



- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Thanks for the reply try67, I did get the dialog working with the help of the reference but it did not have an example like the one you provided to put the result in a text field.
I inserted your code and replaced what i believe is applicable terms like txt1 for the item id of my list and took this.getfield(test).value and replaced test with the name of my text field. Now i get a result in the text field that says "object aggregate".
Let me say that i know almost nothing about java. I first laid eyes on it 3 weeks ago when i started this. I say this because if i did something totally stupid when inserting the code, it will be understood why. lol
So using the new code provided above my script now looks like below.

var testValue;

var dialog = {
// This dialog box is called when the dialog box is created
initialize: function(dialog) {
this.loadDefaults(dialog);
},
// This dialog box is called when the OK button is clicked.

// dialog code...
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
testValue = results["subl"];
this.Date = results["txt1"];
this.exhibitValue = results["txt2"];
this.datebilled = results["txt4"];
this.Outsourced = results["txt5"];
var elements = dialog.store()["subl"];
for(var i in elements) {
if ( elements[i] > 0 ) {
app.aleert("You chose \"" + i
+ "\", which has a value of " + elements[i] );
}
}
},
loadDefaults: function (dialog) {
dialog.load({
subl:
{
"Donations": +1,
"Office Supplies": -2,
"Outsourced Services": -3,
"Paper": -4,
"Telecommunications": -5,
"Utilities": -6
}
})
},


description:
{
name: "VVVVVVVVVVVVVVVVVVV", // Dialog box title
elements:
[
{
type: "view",
elements:
[
{
name: "TEST: ",
type: "static_text",
},
{
item_id: "subl",
type: "popup",
width: 200,
},
{
name: "Date: ",
type: "static_text",
},
{
item_id: "txt1",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},
{
name: "Outsourced: ",
type: "static_text",
},
{
type: "radio",
item_id: "txt5",
name: "No",
group_id: "g1",
width: 200,
height: 25
},
{
type: "radio",
item_id: "txt5",
name: "Yes",
group_id: "g1",
width: 200,
height: 25
},
{
name: "GL Code: ",
type: "static_text",
},
{
item_id: "txt2",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},
{
name: "Date invoiced on: ",
type: "static_text",
},
{
item_id: "txt4",
type: "edit_text",
multiline: true,
width: 300,
height: 20
},
{
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel"
},
]
},
]
}
};


if(event.source.forReal && (event.source.stampName == "#caseandnumfill"))
{
if ("ok" == app.execDialog(dialog))
{
var cMsg = dialog.Date;
event.value = "Date:\n" + cMsg;
event.source.source.info.exhibit = cMsg;

cMsg = "GL Code:\n" + dialog.exhibitValue;
this.getField("ExhibitNumFieldF").value = cMsg;

cMsg = "Bill Date:\n" + dialog.datebilled;
this.getField("datebilled").value = cMsg;

cMsg = "Outsourced:\n" + dialog.Outsourced;
this.getField("Outsourced").value = cMsg;

this.getField("subl").value = testValue;
}
}

try67
Expert
Registered: Oct 30 2008
Posts: 2398
Drop-downs and other such elements in a dialog return an Aggregate object. If you wish to extract the selected value from that, use the elements object and for-loop that you have further down the script. Something like this:

var elements = dialog.store()["subl"];
for(var i in elements) {
if ( elements[i] > 0 ) {
testValue = elements[i];
}
}

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Thank you so much try67, that worked. I am getting the numeric response which makes sense as thats what it was returning in the java popup previously. How can i change that so it returns the actual name instead of a value? I tried replacing the number values with the word but that didnt work.
Also would you have the know how to change the result returned from the radio selection? Right now its true/false i would like to make it yes/no
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can't change the value that is returned. You need to convert it back to your actual values elsewhere.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Can you show me how to do that please? I really do appreciate your help!
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
You just need to add some code that converts it back to whatever values you want to use.
For example, in the dialog you have you load these values to the list:
"Acrobat Professional": +1,
"Acrobat Standard": -2,
"Adobe Reader": -3

So if you get back 1, you know "Acrobat Professional" was selected, 2 means "Acrobat Standard" and 3 means "Adobe Reader"...

var textValue;
if (testValue==1) textValue = "Acrobat Professional";
else if (testValue==2) textValue = "Acrobat Standard";
else if (testValue==3) textValue = "Adobe Reader";

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

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Success! Thank you so much! That leaves one fix which is returning Yes/No result instead of true/false on the radio selection. Can you solve that one for me also?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Just do the same. Convert it afterwards from Yes/No to true/false.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Ok I kinda got it. Without the code it reports true/false but with the code it reports Yes for both. Here is what i did with the code. Seemed pretty straight forward but im missing something. Was i suppose to add something in the commit area?
If so what is it as testValue is already taken?

var textValue;
if (testValue==true) textValue = "Yes";
else if (testValue==false) textValue = "No";
this.getField("Outsourced").value = textValue;
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I thought you wanted to do it the other way around... converting from Yes/No to true/false...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Hoyane
Registered: Nov 26 2011
Posts: 33
Figured it out just had to define a new
testValue2 = results["txt5"];
and get rid of
this.Outsourced = results["txt5"];

Here is the final code for anyone looking in the future.


var testValue;

var dialog = {
// This dialog box is called when the dialog box is created
initialize: function(dialog) {
this.loadDefaults(dialog);
},
// This dialog box is called when the OK button is clicked.

// dialog code...
commit:function (dialog) { // called when OK pressed
var results = dialog.store();
this.Date = results["txt1"];
testValue = results["txt2"];
testValue2 = results["txt3"];
this.datebilled = results["txt4"];
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: "Billing", // Dialog box title
elements:
[
{
type: "view",
elements:
[
{
name: "Date: ",
type: "static_text",
},
{
item_id: "txt1",
type: "edit_text",
multiline: false,
width: 120,
height: 20
},
{
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: "Date invoiced on: ",
type: "static_text",
},
{
item_id: "txt4",
type: "edit_text",
multiline: false,
width: 120,
height: 20
},
{
type: "ok_cancel",
ok_name: "Ok",
cancel_name: "Cancel"
},
]
},
]
}
};


if(event.source.forReal && (event.source.stampName == "#Billing"))
{
if ("ok" == app.execDialog(dialog))
{
var cMsg = dialog.Date;
event.value = "Date:\n" + cMsg;
event.source.source.info.exhibit = cMsg;

cMsg = "Bill Date:\n" + dialog.datebilled;
this.getField("datebilled").value = cMsg;

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

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

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