Home > Survey Creation > How to: Control Attachment names through script

How to: Control Attachment names through script


When capturing photos, videos or sounds, SurveyToGo will automatically generate the attachment name in order to make it unique. While usually there is no importance for the attachment name, sometimes there might be and there might also be a need for you to control the name the attachment is given.

For this purpose, you can utilize a special call back function that enables you to override the default name and assign your own name to the attachment.

Using the “OnGetAttachmentName” call back function

To use the OnGetAttachmentName call back you need to write the following call back function in the “Advanced scripts” of your survey:

OnGetAttachmentName – this call back allows you to alter the name of the attachment that will be generated. It is called each time an attachment is captured and just before the engine decides on the name. Here is an example of the call back function:

function OnGetAttachmentName(inFilePath, inName, inQuestionAttachmentCount, inGlobalAttachmentCount)
var retVal = “PHOTO_Q_”+CurrQues+”_ATTACH_NUMBER_”+inQuestionAttachmentCount+”.jpg”;
return retVal;



Parameter Description
inFilePath The full path of the local attachment file created on the device
inName The name of the attachment as given by SurveyToGo
inQuestionAttachmentCount The number of attachments in the current question (including this one)
inGlobalAttachmentCount The number of attachments in the interview

The above function will generate attachment names such as “PHOTO_Q_3_ATTACH_NUMBER_1” utilizing the index of the current question and the number of attachments. You can use any survey logic function in this code.

Important Note: Please make sure you provide the extension name as should be per the file type generated. SurveyToGo doesn’t complete the extension automatically.

Visit us at: http://www.dooblo.net

Categories: Survey Creation
  1. Luis Jovellar
    February 18, 2013 at 10:40 am

    I have copy-pasted the function and it does not work. Do I need anything else?.
    Thank you.

    • July 7, 2013 at 7:44 am

      Hi, please could you send any questions to support@dooblo.com? this will open up a support ticket for your convenience.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: