web stats
Using default parameter values in Code Templates - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-19-2015, 07:16 AM
ehaberman ehaberman is offline
OBX.1 Kenobi
 
Join Date: Oct 2013
Location: Massachusetts, USA
Posts: 29
ehaberman is on a distinguished road
Default Using default parameter values in Code Templates

Rather than modifying every channel that currently uses a code template, I would like to add a parameter that, if not provided, will create an empty array. My original code template was one that would put a file onto an SFTP server using the JSch library, accepting string parameters for user ID, user password, IP address of the destination SFTP server, port number, source file name, destination file name, source file path, and destination file path. I would like to add a parameter that would hold a certificate used in authentication as a byte array. This is less common in my current use cases, so I would like to default this to an empty array.

I've tried defining the function like this:
Code:
function putSftp(userID, userPW, sFtpIP, sFtpPort, fileStr, destfileStr, fileRemoteDir, fileSrcDir, cert = [])
The response that I get when validating the script or saving the code template is:
"Error on line 5: missing ) after formal parameters"

Any thoughts on this one? Is there a better approach through this library?
Reply With Quote
  #2  
Old 06-19-2015, 08:05 AM
clinjohn clinjohn is offline
OBX.2 Kenobi
 
Join Date: Apr 2015
Posts: 95
clinjohn is on a distinguished road
Default

If the parameter is not provided by the calling script, it will be an undefined argument in the function. You should be able just to add the extra parameter without qualifying it in the function call and set it as an array inside the function. Something like this:

function putSftp(userID, userPW, sFtpIP, sFtpPort, fileStr, destfileStr, fileRemoteDir, fileSrcDir, cert) {
if (cert == undefined) {
cert = [];
}
// rest of the function
}
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -8. The time now is 09:57 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation