Hey,
I did the following on a training form so that the user could click a button and the data would be populated in the field or removed from the field. Not sure if it will help you...
All code is VBScript...
Sub ClearDataFields_OnClick()
'Write your code here
PopDefaults xDocument.view.name, True
End Sub
Sub PopDataFields_OnClick()
PopDefaults xDocument.view.name, False
End sub
Sub PopDefaults(ByVal sViewName, bRemoveData)
'purpose to populate default values based on which view you
' are in. If bRemoveData is true, clear fields
Dim sTxt
Select Case UCase(sViewName)
Case "FORMATFIELDS"
PopFieldValue "//my:ChainID", "1001-11-11", bRemoveData
PopFieldValue "//my:CostCenter", "01255", bRemoveData
PopFieldValue "//my:DateControl", "2006-06-01", bRemoveData
PopFieldValue "//my:DIVNum", "3015", bRemoveData
PopFieldValue "//my:DeptDivNo", "3001", bRemoveData
PopFieldValue "//my:EMPID", "101256", bRemoveData
PopFieldValue "//my:EIN", "11-5533667", bRemoveData
PopFieldValue "//my:SAP_GLCode", "1111-12345678-22668", bRemoveData
PopFieldValue "//my:PhoneNumber", "(336) 741-5000", bRemoveData
PopFieldValue "//my:EmpName", "Jane Q Doe", bRemoveData
PopFieldValue "//my:SISNo", "100111", bRemoveData
PopFieldValue "//my:SSN", "333-22-3333", bRemoveData
PopFieldValue "//my:TerritoryNo", "400112", bRemoveData
Case "REPEAT"
If bRemoveData = False Then
AddRepeatingSection 2, "QTYS"
AddRepeatingSection 2, "PLANNED_MEETS"
AddRepeatingSection 2, "EMPLOYMENT_HISTORY"
'AddRepeatingSection 3, "POSITIONS_HELD"
Else
RemoveRepeatingSection 1, "QTYS"
RemoveRepeatingSection 1, "PLANNED_MEETS"
RemoveRepeatingSection 1, "EMPLOYMENT_HISTORY"
End If
case Else
End Select
End Sub
Sub PopFieldValue(sFieldName, sValue, bRemoveData)
'to populate the value in the field that is off the root node
Dim oField
Set oField = XDocument.DOM.SelectSingleNode(sFieldName)
'must remove xsi:nil attribute if necessary
'required for dates and numeric values
'add the value or remove it
If bRemoveData = False then
If oField.getAttribute("xsi:nil") Then
oField.removeAttribute("xsi:nil")
End If
oField.Text = sValue
Else
If sFieldName <> "//my:DateControl" Then
oField.Text = ""
Else
Dim xmlNil
Set xmlNil = oField.ownerDocument.createNode(2, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance")
xmlNil.text = "true"
oField.Text = ""
oField.setAttributeNode(xmlNil)
End if
end If
End Sub
Function AddRepeatingSection(num, elmName)
'Adds specified number of elements to repeating table or section.
'Parameters:
'num is number of sections/rows to add
' elmName is name of repeating area as shown in datasource task pane (without the "my:" prefix).
Dim secPath, oSecGrp, oSecItem, oClone
secPath = "//my:" & elmName
Set oSecGrp = XDocument.DOM.selectNodes(secPath)
If oSecGrp.length > 0 Then
Set oSecItem = oSecGrp.Item(0)
i = 0
Do Until i = num
'Clone the first row/section.
Set oClone = oSecItem.cloneNode(True)
'Append section at end of nodeset.
oSecItem.parentNode.insertBefore oClone, oSecGrp.Item(oSecGrp.length + i + 1)
i = i + 1
Loop
End If
End Function
Function RemoveRepeatingSection(num, elmName)
'Removes elements to repeating table or section leaving 1 default section or table
'Parameters:
' elmName is name of repeating area as shown in datasource task pane (without the "my:" prefix).
Dim secPath, oSecGrp, oSecItem, oClone
secPath = "//my:" & elmName
Set oSecGrp = XDocument.DOM.selectNodes(secPath)
If oSecGrp.length > 0 Then
Set oSecItem = oSecGrp.Item(0)
'i = 0
i = oSecGrp.length
Do Until i = num
'Remove section at end of nodeset.
oSecItem.parentNode.removeChild oSecGrp.Item(oSecGrp.length - i + 1)
i = i - 1
Loop
End If
End Function