SaveTemplate

Creates a new journal template, or updates an existing journal template.

Caution!

To successfully call SaveTemplate, the connected user must be assigned to the Journals Administrator role.

The arguments for template line items consist of arrays. The arrays have a one-to-one correspondence; for example, the second elements in the varadAmount and vararlAccount arguments’ arrays specify the amount and account for a template’s second line item.

SaveTemplate takes a Double array for the template’s line item’s amounts. To create a template by passing a String array of amounts, use SaveTextTemplate instead of SaveTemplate. The methods are almost identical; the only difference is the subtype of the line item amount array. For more information, see SaveTextTemplate.

Syntax

<IHsvJournalsEx>.SaveTemplate nType, nAttribute, bstrLabel, bstrDescription, bstrGroup, lSingleEntity, lSingleParent, nTemplateType, lValueID, vararnDebitCreditUnit, varadAmount, vararbstrDescription, vararlEntity, vararlParent, vararlAccount, vararlICP, vararlCustom1, vararlCustom2, vararlCustom3, vararlCustom4, plTemplateID

Argument

Description

nType

Integer (ByVal). Specifies the journal type of the journals that will be created from the template. Pass one of the HFMConstants type library constants listed in Journal Type Constants.

nAttribute

Integer (ByVal). Specifies whether journals created from the template must be balanced. Pass one of the Balance Type Constants.

bstrLabel

String (ByVal). The label for the template.

bstrDescription

String (ByVal). The description for the template. You can pass a blank string if there is no description.

bstrGroup

String (ByVal). The journal group to which the journals created from the template will be assigned. You can pass a blank string if the journals will not be assigned to a journal group

lSecurityClass

Long. The ID of the security class for the template.

Tip:

To get the ID from a security class name, use HsvSecurityAccess.GetSecurityClassLabel.

lSingleEntity

Long (ByVal). For single entity journal templates, specify the member ID of the journal’s base entity. For multi-entity journal templates, pass a value of -1.

lSingleParent

Long (ByVal). For single entity journal templates, specify the member ID of the journal’s parent entity. For multi-entity journal templates, pass a value of -1.

nTemplateType

Integer (ByVal). Determines whether the template is standard or recurring. Pass one of the HFMConstants type library constants listed in Template Type Constants.

lValueID

Long (ByVal). For recurring templates, specify the member ID of the template’s Value dimension member.

Since standard templates are not assigned a Value dimension member, specify -1 when SetTemplate is called for a standard template.

vararnDebitCreditUnit

Integer array (ByVal). Specifies whether the line items are debits or credits. Pass one of the HFMConstants type library constants listed in Debit/Credit Constants.

varadAmount

Double array (ByVal). The amounts of the line items.

vararbstrDescription

String array (ByVal). The descriptions of the line items.

vararlEntity

Long array (ByVal). The member IDs for the base entities of the line items. For single-entity items, set the IDs in this array to the same member ID that is in the lSingleEntity argument.

vararlParent

Long array (ByVal). The member IDs for the parent entities of the line items. For single-entity items, set the IDs in this array to the same member ID that is in the lSingleParent argument.

vararlAccount

Long array (ByVal). The member IDs of the accounts for the line items.

vararlICP

Long array (ByVal). The member IDs of the line items’ Intercompany Partner dimension members.

vararlCustom1

Long array (ByVal). The member IDs of the line items’ Custom 1 dimension members.

vararlCustom2

Long array (ByVal). The member IDs of the line items’ Custom 2 dimension members.

vararlCustom3

Long array (ByVal). The member IDs of the line items’ Custom 3 dimension members.

vararlCustom4

Long array (ByVal). The member IDs of the line items’ Custom 4 dimension members.

plTemplateID

Long. The purpose of this argument depends upon whether you are creating a new template or updating an existing template:

  • For a newly created template, this argument returns the automatically-generated ID of the template.

  • To update an existing template, pass the template’s ID with this argument. You can get template IDs with GetJournalTemplateItemID; for details, see GetJournalTemplateItemID.

Example

This example defines a custom function named NewTemplate that creates new templates from an existing template, changing the entities while carrying over the other properties of the existing template. The existing template’s name and the new template’s name, description, and Entity dimension member IDs are passed as the function’s arguments. The example calls GetTemplate to get the existing template’s information.

Function NewTemplate(sTemplate As String, sNewLabel As String, _
   sDesc As String, lNewEntID As Long, lNewParID As Long) As Long
Dim cHsvJournals As HsvJournals, iType As Integer
Dim cIHsvJournalEx As IHsvJournalsEx, lTempID As Long
Dim sLabel As String, sDescHead As String, sGroup As String
Dim lSecID As Long, lSingleEnt As Long, lSinglePar As Long
Dim iTempType As Integer, lVal As Long, vaEntryIDs, vaDebCredUnit
Dim vaAmt, vaItemDesc, vaEnt, vaPar, vaAcct, vaICP, vaCust1
Dim vaCust2, vaCust3, vaCust4, lNewTempID As Long
Dim iAttr As Integer, laNewEnt() As Long, laNewPar() As Long
Dim lUpBounds As Long
'm_cSession is an HsvSession object reference
Set cHsvJournals = m_cSession.Journals
Set cIHsvJournalEx = m_cSession.Journals
lTempID = cHsvJournals.GetJournalTemplateItemID(sTemplate)
cIHsvJournalEx.GetTemplate lTempID, iType, iAttr, sLabel, _
   sDescHead, sGroup, lSecID, lSingleEnt, lSinglePar, _
   iTempType, lVal, vaEntryIDs, vaDebCredUnit, vaAmt, _
   vaItemDesc, vaEnt, vaPar, vaAcct, vaICP, vaCust1, _
   vaCust2, vaCust3, vaCust4
lUpBounds = UBound(vaEnt)
'Create the entity ID arrays that will be passed to SaveTemplate
ReDim laNewEnt(lUpBounds)
ReDim laNewPar(lUpBounds)
For i = LBound(vaEnt) To lUpBounds
laNewEnt(i) = lNewEntID
laNewPar(i) = lNewParID
Next i
cIHsvJournalEx.SaveTemplate iType, iAttr, sNewLabel, _
   sDesc, sGroup, lSecID, lNewEntID, lNewParID, _
   iTempType, lVal, vaDebCredUnit, vaAmt, vaItemDesc, _
   laNewEnt, laNewPar, vaAcct, vaICP, vaCust1, vaCust2, _
   vaCust3, vaCust4, lNewTempID
NewTemplate = lNewTempID
End Function