I am essentially doing the same thing. When the user clicks the email
button here is what happens.
* Sets a filename field, this field is created so it will be unique.
-FirstnameLastname-mmddyy-hhmmss
* Then using code and an Email Dataconnection, create an email, which
has:
- CC
- Subject
- Intro.
In the intro I have a link to the form in the form library.
The email is sent using Dataconnection
If the email is not canceled submit to WSS.
You will need 2 data connections.
1-Submit, submit to a WSS lirary
2-Email, I filled in the TO field, but this can be done in the code
below.
This is really my first stab at scripting in InfoPath so if anyone has
any suggestions, please let me know.
Here is the code, VBScript. Watch for line wrap.
Sub Email_OnClick(eventObj)
'check format on Phone and change if not XXX-XXX-XXXX
tPhone = XDocument.DOM.selectSingleNode("//my
![Stick Out Tongue :p :p](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
honeNumber").text
If len(tPhone) = 10 then
strPhone = left(tPhone,3) & "-" & mid(tPhone,4,3) & "-" &
right(tPhone,4)
XDocument.DOM.selectSingleNode("//my
![Stick Out Tongue :p :p](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
honeNumber").text = strPhone
ElseIf len(tPhone) < 10 then
Msgbox("Please enter in full phone number, including Area Code")
exit Sub
End If
If XDocument.DOM.selectSingleNode("//my:FileName").text = "" then
'Get Date/Time to allow for unique file name
strNow = Now
'Add 0 if Hour < 10
If len(Hour(strNow)) = "1" then
strHour = "0" & Hour(strNow)
Else
strHour = Hour(strNow)
End If
'Add 0 if Min < 10
If len(Minute(strNow)) = "1" then
strMinute = "0" & Minute(strNow)
Else
strMinute = Minute(strNow)
End If
'Add 0 if Seconds < 10
If len(Second(strNow)) = "1" then
strSecond = "0" & Second(strNow)
Else
strSecond = Second(strNow)
End If
'Set Time to equal HHMMSS
strTime = strHour & strMinute & strSecond
'Add 0 if month does not have 2 characters
If len(month(strNow)) = "1" then
strMonth = "0" & month(strNow)
Else
strMonth = month(strNow)
End If
'Add 0 if day does not have 2 characters
If len(day(strNow)) = "1" then
strDay = "0" & day(strNow)
Else
strDay = day(strNow)
End If
'Set Date to equal MMDDYY
strDate = strMonth & strDay & right(year(strNow),2)
'Combine the first and last names.
strFullName =
trim(XDocument.DOM.selectSingleNode("//my:firstName").text) & _
Trim(XDocument.DOM.selectSingleNode("//my:lastName").text)
'Set the file name = FullName-MMDDYY-HHMMSS
TheFileName = strFullName & "-" & strDate & "-" & strTime
'Set the filename Field
XDocument.DOM.selectSingleNode("//my:FileName").text = TheFileName
End If
'Email the link to the document
strFirstName = XDocument.DOM.selectSingleNode("//my:firstName").text
strUserName = XDocument.DOM.selectSingleNode("//my:userName").text
If NOT instr(strUserName,"@") then
strUsername = strUsername & "@ci.charlotte.nc.us"
End If
Set objEmail = XDocument.DataAdapters("Email") 'Requires a
dataconnection named Email
objEmail.CC = strUserName
objEmail.Subject = "BSS-IT Service Request"
objEmail.Intro = strFirstname & "," & vbcr _
& vbcr _
& "Your service request has been submitted to IT." & vbcr _
& "To view your pending request please click here:
http://Website/itservices/BSSITSRform/" & TheFileName & ".xml" & vbcr _
& "To view all assigned requests you have submitted, please click here
http://WebSite/itservices/BSSITSRForm/Forms/MyItems.aspx" & vbcr _
& vbcr _
& "You will be notified by email when your request has been assigned
to member of IT. " & vbcr _
& "If you have any questions about the request or would like to make
changes, please contact" & vbcr _
& "mailto:
[email protected]?subject=" & TheFileName & " by clicking
the link or send an email " & vbcr _
& "to itservices and include the file name " & TheFileName & " in the
subject." & vbcr _
& vbcr _
& "Thank you," & vbcr _
& "IT Service Request Admin"
On error resume next
objEmail.Submit()
errNum = err.number
on error goto 0
If errNum <> 0 then
Msgbox ("Your request can not be submitted unless you click *SEND* on
the email Confirmation window." & vbcr _
& "Please resend your request and click Send on the confirmation
Window.")
XDocument.DOM.selectSingleNode("//my:FileName").text = ""
Exit Sub
Else
'Submit to WSS if email is successful.
strNow = Year(Now) & "-" & Month(Now) & "-" & Day(Now) & "T" &
Hour(Now) & ":" & Minute(Now) & ":" & Second(Now)
XDocument.DOM.selectSingleNode("//my:emailedOnDate").text = strNow
XDocument.DOM.selectSingleNode("//my:Status").text = "IsReadySubmit"
XDocument.DOM.selectSingleNode("//my:formStatus").text = "Pending"
Set objSubmit = XDocument.DataAdapters("Submit")'Requires a
Dataconnection named Submit
On error Resume Next
objSubmit.Submit()
On error Goto 0
msgbox ("Thank you," & vbcr _
& "Your IT Service Request has successfully been submitted," & vbcr _
& "if prompted, please click NO to the next message dialog." & vbcr _
& "Clicking yes will resubmit the form with a different name without
notifiying IT.")
'Close the document after submit
XDocument.View.Window.Close()
End If
End Sub