cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to add placeholders in Localized Resource text?

Former Member
0 Kudos

Hi,

I am writing a script for validating the file type of attachment file in an Attachment extension field. We have to restrict users from selecting any file other than the allowed types. If user selects a different file, I want to display an error mesage like "File type <selected type> is not supported"

Can I add a localized resource with a placeholder for <selected type>? I want the <selected type> in the error message to be dynamically populated by the value I pass to it from the script. is this possible? if yes, how?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Got it after lots of trial and error. I created a new Localised Resource with a value like this:

"File type {0} is not a supported type..."

The {0} in the message is replaced by the actual file type using a message modifier string array (details in Reference Guide iAPI section for ChainedException). Here is the code snippet that did the job for me:

Set errorId to the localised resource id then:

msgMod = new String[1];

attach = doc.getExtensionField("W9_ATTACH").get();

if (hasValue(attach)){

    String fileName = attach.getDisplayName();

    logIt("*** User has selected W9 attachment file " + fileName + " ***", 1);

    //Get the file extension

    String extension = "";

    int i = fileName.lastIndexOf('.');

    if (i >= 0)

        extension = fileName.substring(i+1);

    logIt("*** File type is " + extension + " ***", 1);

    //Validate - throw error if the type is not PDF, BMP, TIF or JPG

    if (!Arrays.asList(new String[] {"PDF", "BMP", "TIF", "JPG", "pdf", "bmp", "tif", "jpg"}).contains(extension)) {

        msgMod[0] = extension;

       ae.chainAtEnd(doc.createApplicationException("W9_ATTACH",bundle,errorId).setMessageModifiers(msgMod));

    }

}

Answers (0)