Dynamic Document Properties

Boomi Script

final String userDefinedPropertyBase = 'document.dynamic.userdefined.'
final String DDP_Template = userDefinedPropertyBase + 'DDP_Template'

for (int docNo = 0; docNo < dataContext.getDataCount(); docNo++) {
    String document = _getTextDocument(dataContext, docNo)
    Properties props = dataContext.getProperties(docNo)
    def jsonDoc = js.parseText(document) 

    // *********** Script functionality ************

    String templateText = props.getProperty( DDP_Template, "")
    if( templateText.length() == 0)
        throw new InvalidParameterException("DDP_Template is empty!")
    ...

Test Class

// Define the Dynamic Property Name respecting the base path
String DDP_TemplateName = Document.userDefinedPropertyBase + "DDP_Template"

Properties prop = new Properties()
prop[ DDP_TemplateName] = (new File(TESTDATA_DIR + "/basicTemplate.html")).getText("UTF-8")

	DataContext inDataContext = DataContext.withDocuments(
	[
		Document.fromFile(TESTDATA_DIR + "basicData.json",  prop )
	]
)

Do not use dynamic map initialization in Groovy:

String DDP_TemplateName = Document.userDefinedPropertyBase + "DDP_Template"
Properties prop = new Properties() [ { **DDP_TemplateName** : "abc" } ]

The Groovy dynamic map initialization [ { key : value } ] will not recognize DDP_TemplateName as a variable but as a dynamic property. This is actually the same code:

String DDP_TemplateName = Document.userDefinedPropertyBase + "DDP_Template"
Properties prop = new Properties() [ { **"DDP_TemplateName"** : "abc" } ]

Last updated