AnsweredAssumed Answered

Setting Dynamic Doc. Prop. to Random Number

Question asked by landan.cerff268249 on Apr 23, 2018
Latest reply on Apr 24, 2018 by landan.cerff268249

Hey all. 

 

I'm currently trying to sort some groovy script out so that it takes a document property of mine, applies a random number to it and then sets that property with that new number. 

I've used the script found here: How to access Dynamic Document Properties using Groovy  but I've modified it to add in the random number generator (nextInt()%*** +**) but I keep getting this error;

 

 

The full code is;  

 

import java.util.Properties;
import java.io.InputStream;

Random rand= new Random()
random_num = rand.nextInt()%9999999 +23

for ( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is = dataContext.getStream(i);
Properties props = dataContext.getProperties(i);

// Retrieve the current property value
propValue = props.getProperty("document.dynamic.userdefined.perNum");

// Modify the value
propValue = random_num;

 

// Store the new property value
props.setProperty("document.dynamic.userdefined.perNum", propValue);
dataContext.storeStream(is, props);
}

The 'perNum' property is located in the step before the scripting, this is just to deal with it coming in null. If null then it's forced in as a 1 and updated with a random number to pass to a map. 

 

 

Any help with this would be amazing. 

 

Many thanks, 

 

Landan

Outcomes