Skip to main content
Sonny AR
Inspiring
March 19, 2024
Answered

Dynamic Stamp Adobe Acrobat

  • March 19, 2024
  • 1 reply
  • 1121 views

Hello Experts,

 

I'm having an issue with a dynamic stamp that I'm working on. It has four dropdown fields, but the text fields are displaying an error message saying "Object Aggregate". I suspect there might be an issue with the commit function idk, but I'm not very experienced with adding dropdown fields to stamps. Could anyone lend a hand and assist me with this?

 

TIA

This topic has been closed for replies.
Correct answer Thom Parker

Now its showing "UNDEFINED"

 

In this code, "ForEach" loop is it correct or there should be "For"? : 

function getListSelect(oLstItems){forEach(nm in oLstItems){if(oLstItems[nm]>0)return nm;};return null;}

 

 

 

 


Excellent catch!! Yes, it should be a for loop.  Here's the corrected code:

 

function getListSelect(oLstItems){for(nm in oLstItems){if(oLstItems[nm]>0)return nm;};return "";}

 

 

 

 

1 reply

Thom Parker
Community Expert
Community Expert
March 19, 2024

Dialog list fields return an object. It's the same object is used to initialize the list. 

 {"Orange":-1, "Pear":-1, "Peach":-1}

 

Except, one of the object elements will have a value of "1", instead of -1. That's the one that has been selected.

You need a function to loop over the object elements and find the one with the non-negative value;

 

function getListSelect(oLstItems){forEach(nm in oLstItems){if(oLstItems[nm]>0)return nm;};return null;}

 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Sonny AR
Sonny ARAuthor
Inspiring
March 19, 2024

Thanks for the reply,

I use negatives values for all items because i don't want to make default selection in dropdown. 

where can i use this function line in my code: 

function getListSelect(oLstItems){forEach(nm in oLstItems){if(oLstItems[nm]>0)return nm;};return null;}

try67
Community Expert
Community Expert
March 19, 2024

Each item must have a unique value. You can't use -1 for all of them. Use +1 for the one you want to have selected by default, then -2 for the next item, -3 for the next, etc.

The code provided by Thom needs to go in the commit function of the dialog object.