Image List In Script Array

Hi,

Cannot find this info anywhere. Can I create and array in a control script that contains all the file names in the templates Images folder?

Why? Because I don’t want to rename PDF’s to match the field in the data. Would prefer a If statement using Includes.

Regards,
S

Not entirely sure what you are looking for but you could create the following in a Control Script:

var images = { 
	AU:'australia.pdf',  
	EG:'egypt.pdf', 
	IN:'india.pdf', 
	JP:'japan.pdf'
};

And fetch values in a User Script like this:

var img = images[ record.fields.countrycode ];
// Example:
// var img = images[ 'AU' ];

Hi Erik,

I’m almost sure what I want is not accessible via a script. I will have ±100 PDF’s named like below but each name will be variable.

4900095 XXXXX YYYYY DDD_GGG AA CCCCCC to Widow or Spouse_excl. vol pensions PAID POLICY.pdf

The number in the beginning of the file name matches the data field SCHEME. I don’t want to rename the PDF to 4900095.pdf so that it works in my current script.

merge.template.contexts.PRINT.sections["Section 2"].background.source = BackgroundResource.RESOURCE_PDF;
merge.template.contexts.PRINT.sections["Section 2"].background.allPages = true;
var resourceUrl = 'images/' + record.fields.SCHEME + '.pdf';
merge.template.contexts.PRINT.sections["Section 2"].background.url = resourceUrl;

What would be ideal is if I could loop through ‘images/’ resource folder, get every image filename into an array, use said array with IF statement & Includes to match the SCHEME number in the beginning of the file name to the SCHEME field in the data mapper.

Answer is probably no, but it would be a great feature I think.

I know I can setup a Workflow process and rename said PDF’s but if this was possible… another step avoided is time saved :slight_smile:

Regards,
S

1 Like

Guess I was oversimplifying things. :wink: You could try the Export Report function in the File menu. This can generate an XML export with all information of the template (including the images). Perhaps you can use this data to create your array (for example via a custom Data Map or XML to JSON converter). Admittedly a bit clunky but it may work.

Ok, so that was a polite NO :joy: Do you think my idea is feasible as a feature?

Your idea is doable but I would just rename them in Workflow. I was just hoping that my idea was hidden in the user guide somewhere :slight_smile:

Regards,
S

Found this on the web. Could that help you?

function ShowFolderFileList(folderspec){
    var fso, f, fc, s;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFolder(folderspec);
    fc = new Enumerator(f.files);
    s = "";

    for (; !fc.atEnd(); fc.moveNext()) {
        s += fc.item();
        s += "<br>";
    }
    return s;
}

Once you have the list, you could search it for a match on the number at the beginning of the file.

Yes, I think it is definitely doable as a feature. Will create an Improvement Request for it.

1 Like

Hi hamelj,

That would be another way of doing it in Workflow. I was hoping for a Template only solution.

Regards,
S

Have you tried it in a control script? I haven’t but nothing to loose by trying…no?

Internal reference [SHARED-82303]. Provide access to the list of image resources from a user/control script (e.g. var images = merge.template.images; ).

1 Like

“ActiveXObject” is not defined." when used in a control script :laughing:

Thanks Erik.

(20 characters for post)

D’ho!!!That is JScript :crazy_face: