Before Save formula
This is the formula that is executed before the service request is saved.
' Formula: fullpath
' Event: Before Save on Service Request
' To enforce Contact Phone and Mobile Number and add full path to Customer Comment when adding service request
‘ Also enforces selection of Impact and Severity
Dim res As Hansen.Core.Result = Result.Success
Dim oContact As Hansen.Resources.IContact
oContact = oPrimaryCall.Contact
Dim phone, mobile As String
Dim IsCustomerCallCreatedByFormula as boolean=false
' to enforce the user that expectation is required
If
(oServiceRequest.Impact.ServiceRequestImpactKey = 0 OR oServiceRequest.Impact.ServiceRequestImpactKey = 1)
And (oServiceRequest.ServiceRequestNumber = 0 OR oServiceRequest.ServiceRequestNumber = 1)
Then
res = new Result(0, ResultSeverity.UserError, "Expectation is required")
Return res
End If
' to enforce the user that effect is required
If
(oServiceRequest.Severity.ServiceRequestSeverityKey = 0
OR oServiceRequest.Severity.ServiceRequestSeverityKey = 1)
And (oServiceRequest.ServiceRequestNumber = 0
OR oServiceRequest.ServiceRequestNumber = 1)
Then
res = new Result(0, ResultSeverity.UserError, "Effect is required")
Return res
End If
'*****NEW CODE FROM CREATION OF CUSTCALL*****
if
oContact.ContactKey = 0 or oContact.ContactKey = 1
then
res = new Result(0, ResultSeverity.UserError, "No validated contact was entered.")
Return res
end if
'*****************************************************************
phone = oContact.DayPhone.Trim()
mobile = oContact.MobileNumber.Trim()
' To enforce the user to enter Contact Phone otherwise throw an exception
If
phone = "" And (oServiceRequest.ServiceRequestNumber = 0
Or oServiceRequest.ServiceRequestNumber = 1)
Then
res = new Result(0, ResultSeverity.UserError, "You must enter Contact Phone")
Else
' To enforce the user to enter Contact Mobile otherwise throw an exception
If
mobile = "" And (oServiceRequest.ServiceRequestNumber = 0
Or oServiceRequest.ServiceRequestNumber = 1)
Then
res = new Result(0, ResultSeverity.UserError, "You must enter Contact Mobile Number")
End If
End If
Dim strDate As String = System.DateTime.Now
Dim strDay As String = System.DateTime.Now.Day
Dim strMonth As String = System.DateTime.Now.Month
Dim strYear As String = System.DateTime.Now.Year
Dim strHr As String = System.DateTime.Now.Hour
Dim strMin As String = System.DateTime.Now.Minute
Dim strSec As String = System.DateTime.Now.Second
If
strDay.Length = 1
Then
strDay = "0" + strDay
End If
If
strMonth.Length = 1
Then
strMonth = "0" + strMonth
End If
If
strHr.Length = 1
Then
strHr = "0" + strHr
End If
If
strMin.Length = 1
Then
strMin = "0" + strMin
End If
If
strSec.Length = 1
Then
strSec = "0" + strSec
End If
Dim strDate24 As String = strDay + "/" + strMonth + "/" + strYear + " " + strHr + ":" + strMin
Dim strUserID As String = oPrimaryCall.UserInfo.UserName.ToUpper() + " " + strDate24
' If inserting service request, then add full path for the customer comment
If
oPrimaryCall.CustomerCallKey = 0 OR oPrimaryCall.CustomerCallKey = 1
Then
If
oPrimaryCall.Comments.Trim() = ""
Then
oPrimaryCall.Comments = FullPath + " (" + strUserID + ")"
Else
oPrimaryCall.Comments = "<P>" + FullPath + "</P><P>Customer Comment: " +
oPrimaryCall.Comments + " (" + strUserID + ")</P>"
End If
Else
Dim oCustomerCallDB
As Hansen.CRM.ICustomerCall = ServerApplication.NewComponent("Hansen.CRM.CustomerCall", oPrimaryCall.UserInfo)
oCustomerCallDB.CustomerCallKey = oPrimaryCall.CustomerCallKey
oCustomerCallDB.LoadByKey()
Dim myOriginalComment
As String = oCustomerCallDB.Comments.Replace("&lt;", "<").Replace("&gt;", ">")
Dim myCComment As String = oPrimaryCall.Comments
If
myCComment = myOriginalComment
And myOriginalComment.IndexOf(oPrimaryCall.UserInfo.UserName.ToUpper()) < 0
Then
oPrimaryCall.Comments = myCComment.Trim().Replace("<P>", "").Replace("</P>", "") & " (" + strUserID & ")"
End If
End If
Return res