Tuesday, October 18, 2011

Script Senarios.doc


ACCOUNT  BC -- Function BusComp_PreCopyRecord () As Integer
''*********************************************************************************
' Author           : Jon Wright
' Created          : 08/10/2001
' Description: This Code prevents users from Copying a CIM Customer.Only a prospect
'                                      Customer can be copied.
'
' Modification History:
' 08/10/2001 - Jon Wright  - Code created
' 12/13/2001 - Jon Wright  - Added Error handling.
' 06/08/2002 - Jason Waugh - Updated error handler to use RaiseErrorText instead of Msgbox
' 11/12/2003 - Dharmesh    - Reorganized
''*********************************************************************************
On Error GoTo ErrorDebug

            BusComp_PreCopyRecord = ContinueOperation

            If GetFieldValue ("Account Status") <> "Prospect" Then
                        BusComp_PreCopyRecord = CancelOperation
                        TheApplication.RaiseErrorText "Only a Prospect Customer can be copied"
            End If

Exit Function

ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_PreCopyRecord Event.  " & Error$
            End Select
                       
End Function







ACCOUNT  BC -- Sub BusComp_CopyRecord
''*********************************************************************************
' Author           : Jon Wright
' Created          : 08/10/2001
' Description: Variable set to be used in BusComp_Predelete code
'
' Modification History:
' 08/10/2001 - Jon Wright  - Code created
' 12/17/2001 - Jon Wright  - Code enhanced to incorporate Siebel Review suggestions
' 06/08/2002 - Jason Waugh - Updated error handler to use RaiseErrorText instead ofMsgbox
' 11/12/2003 - Dharmesh    - Reorganized
''*********************************************************************************
           
On Error GoTo ErrorDebug   
           
            gsNew = "Y"

Exit Sub

ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_CopyRecord Event.  " & Error$
            End Select
                       
End Sub





ACCOUNT  BC -- Sub BusComp_NewRecord
''*********************************************************************************
' Author           : Jon Wright
' Created          : 07/27/2001
' Description: Variable set to be used in BusComp_Predelete code
'
' Modification History:
' 07/27/2001 - Jon Wright  - Code created
' 12/17/2001 - Jon Wright  - Code enhanced to incorporate Siebel Review suggestions
' 06/08/2002 - Jason Waugh - Updated error handler to use RaiseErrorText instead of Msgbox
' 11/12/2003 - Dharmesh    - Reorganized
''*********************************************************************************
On Error GoTo ErrorDebug
           
            gsNew = "Y"
                       
Exit Sub

ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_NewRecord Event.  " & Error$
            End Select
           
End Sub




ACCOUNT  BC --  Sub BusComp_Associate
''*********************************************************************************
' Author           : Jeff Dicks 
' Created          : 06/25/2001
' Description: When an account is associated to a Contact Through MVG from Contact Screen
'              this Code obtains the primary address of the Account, and associates this
'              address With the Contact. 
'
' Modification History:
' 06/06/2001 - Jeff Dicks - Code created
' 12/17/2001 - Jon Wright - Code enhanced to incorporate Siebel Review suggestions
' 06/09/2002 - Jason Waugh- Updated error handler to use RaiseErrorText instead
'                           of Msgbox.
' 09/19/2002 - Gaurav     - Updated code to destroy objects after calls
'                           to RaiseError And RaiseErrorText.
' 11/12/2003 - Dharmesh   - Removed Unused code and Reorganized
''*********************************************************************************
On Error GoTo ErrorDebug

            Dim sContactId As String
            Dim sAddrId    As String
           
            Dim bcContact  As BusComp
            Dim bcMvg      As BusComp
            Dim bcAssoc    As BusComp

            '***Code only needs to execute if Contact is the business object being used in conjunction with Account.
            If BusObject.Name = "Contact" Then
           
                        Set bcContact = BusObject.GetBusComp("Contact")     '**Get handle on Contact Bus Comp       
                        sContactId = bcContact.GetFieldValue("Id")          '**Obtain the Id of the current Contact
                       
                        sAddrId  = GetFieldValue("Primary Address Id")       '**Obtain the id of the Primary Address of the Account
                        If sAddrId = "No Match Row Id" Then GoTo ExitSub    '**If no address associated w/Account, exit codthe code
                       
                        Set bcMvg     = bcContact.GetMVGBusComp("Personal Street Address") '**Get handle on Personal Address Bus Comp
                        Set bcAssoc   = bcMvg.GetAssocBusComp               '**Get handle on Association Bus Comp
                       
                        '***If the address associated with this account is already associated with the Contact
                        '***do not attempt to associate it again - Exit the sub
                        With bcMvg
                                    .ClearToQuery
                                    .SetSearchSpec "Id", sAddrId
                                    .ExecuteQuery
                                    If .FirstRecord = 1 Then GoTo ExitSub
                        End With
                       
                        '***If the address IS NOT already associated with the contact, create an association
                        '***after the existing addresses already associated with this contact.
                        With bcAssoc
                                    .ClearToQuery
                                    .SetSearchSpec "Id", sAddrId
                                    .ExecuteQuery
                                    .Associate NewAfter
                        End With
                       
            End If

GoTo ExitSub

ErrorDebug:
            Set bcAssoc   = Nothing
            Set bcMvg     = Nothing
            Set bcContact = Nothing
           
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_Associate Event.  " & Error$
            End Select
           
ExitSub:
           
Set bcAssoc   = Nothing
Set bcMvg     = Nothing
Set bcContact = Nothing

End Sub




ACCOUNT  BC -- Function BusComp_PreDeleteRecord () As Integer
''*********************************************************************************
' Author           : Jon Wright
' Created          : 07/27/2001
' Description: This Code prevents users from deleting a Customer except when they
'                                      are merging two Customers or Undoing a new record created.
'
' Modification History:
' 07/27/2001 - Jon Wright  - Code created
' 08/10/2001 - Jon Wright  - Enhanced code to check for NewRecord event.
' 08/17/2001 - Jon Wright  - Enhanced code to continue if called from Contact screen.
' 12/13/2001 - Jon Wright  - Added Error handling.
' 06/09/2002 - Jason Waugh - Updated error handler to use RaiseErrorText instead of Msgbox
' 06/11/2002 - Govind      - Code added for All Account MVG Applet button delete.
' 06/27/2002 - Govind      - Enhanced code fix the error %1
' 11/12/2003 - Dharmesh    - Reorganized the code
''*********************************************************************************

On Error GoTo ErrorDebug

Dim sView As String
'Dim sOwnerId As String
'Dim sLoginId As String
Dim sAcctStat As String
                                               
            BusComp_PreDeleteRecord = ContinueOperation
                                                           
            '*** Check the variables from BusComp_PreInvoke, BusComp_NewRecord and
            '*** BusComp_CopyRecord to see if the delete is for a merge or UndoRecord
            If gsMerge = "Y" Then
                        gsMerge = "N"
                        gsNew = "N"
            Elseif gsNew = "Y" OR BusObject.Name = "Contact" Then
                        gsNew = "N"
            Else
                        sView = TheApplication.ActiveViewName
                        'sLoginId = TheApplication.LoginId()
                        'sOwnerId = GetFieldValue("Created By")
                        sAcctStat = GetFieldValue("Account Status")

                        If sAcctStat = "Prospect" And (sView = "Account Admin View across Organization SBC" OR sView = "All Account Admin View SBC") Then
                                    Exit Function
                        Else
                                    '*** Prevent a Customer Delete
                                    BusComp_PreDeleteRecord = CancelOperation
                                    TheApplication.RaiseErrorText "You cannot delete a Customer"
                                    Exit Function
                        End If
            End If
                                               
Exit Function
                                                           
ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_PreDeleteRecord Event.  " & Error$
                        End Select                                          
           
End Function




ACCOUNT  BC -- Sub BusComp_WriteRecord
''*********************************************************************************
' Author           : Jon Wright
' Created          : 08/27/2001
' Description: Variable set to be used in BusComp_Predelete code
'
' Modification History:
' 08/27/2001 - Jon Wright  - Code created
' 12/13/2001 - Jon Wright  - Added Error handling.
' 06/09/2002 - Jason Waugh - Updated error handler to use RaiseErrorText instead of Msgbox
' 11/12/2003 - Dharmesh    - Reorganized
''*********************************************************************************
On Error GoTo ErrorDebug

            gsNew = "N"
           
Exit Sub

ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_WriteRecord Event.  " & Error$
            End Select
           
End Sub


ACCOUNT  BC --- Function BusComp_PreInvokeMethod (MethodName As String) As Integer
''*********************************************************************************
' Author           : Jon Wright
' Created          : 07/27/2001
' Description: This Code ensures that only Prospect Customers could be merged into
'                                      another Customer, and the user will not be able to select more than
'                                      two record for merging.
'
' Modification History:
' 07/27/2001 - Jon      - Code created
' 08/17/2001 - Jon      - Enhanced code to set multi-location flag on target
'                                                                         account when merge takes place.
' 06/09/2002 - Jason    - Updated error handler to use RaiseErrorText instead
'                         of Msgbox.
' 09/10/2002 - Gaurav   - Code added to update flag and store module of deleted
'                         customer for workflow to update.
' 10/02/2002 - Govind   - Code added to update the Source Record Info to Target Record
'                                     while merging two records
' 10/07/02   - Jason    - Code Enhanced to initialize variables for Contact
'                         Primary code in Invoke Method.
' 05/06/03   - Gaurav   - Code enhanced to update the attachment flag
' 11/06/03   - Dharmesh - Code added to update Account plan related fields while merging
' 11/12/03   - Dharmesh - Reorganizaed the code for better understanding
' 12/02/03   - Dharmesh - Added code to update Profile WF Flag
' 04/27/04   - Dharmesh - Commented code which checks for merging through Interface Script
' 05/05/04   - Govind & Hiren  - Code Removed Related for Primary Contact flag
' 04/27/05   - Hiren    - Inactivated a single line of code for location clean up
' 05/09/05   - Hiren    - Inactivated Line 88,156,157
'************************************************************************************
On Error GoTo ErrorDebug

BusComp_PreInvokeMethod = ContinueOperation

'** Execute following code only while using merge records
If MethodName = "VerifyCanMerge" Then

            'Varibale to store values from Source Customer
            Dim sSrcId                      As String
            Dim sSrcAPStatus    As String
            Dim sSrcAPDate      As String
            Dim sTarId                      As String
            Dim sTarAPStatus    As String
            Dim sTarAPDate      As String
            Dim sTarPfWFflag    As String
           
            'Varibale to store values from Source Customer only for interface script
            Dim sSrcPhone                       As String
            Dim sSrcFax                           As String
            Dim sSrcLastCon                    As String
            Dim sSrcCustAlias      As String
            Dim sSrcWebAdd                  As String
            Dim sSrcOwner                      As String

    '*** Don't Allow merge if more than two records are selected
            FirstSelected
            NextSelected
            If NextSelected Then
                        gsMerge = "N"
                        BusComp_PreInvokeMethod  = CancelOperation
                        TheApplication.RaiseErrorText "Please do not select more than two records for Merging."
            End If
           
'*****************************************************
'Performing Operations on the Source record
'*****************************************************
            FirstSelected

    '*** Allowing merge only if Source Customer is Prospect
            If GetFieldValue ("Account Status") <> "Prospect" Then
                        gsMerge = "N"
                        BusComp_PreInvokeMethod  = CancelOperation
                        TheApplication.RaiseErrorText "Only a Prospect Customer can be merged into another Customer"
            End If

            sSrcId        = GetFieldValue("Id")
            sSrcAPStatus  = GetfieldValue("AP Status SBC")
            sSrcAPDate    = GetfieldValue("AP Last Revised SBC")
                       
    '**   Added for Merge using external VB Script. Will not be used for GUI
'           If TheApplication.getSharedGlobal("gsAppServer") = "N" Then
                        sSrcPhone     = GetfieldValue("Main Phone Number") ' *** Store Phone of the deleted Customer
                        sSrcFax       = GetfieldValue("Main Fax Number") ' *** Store fax of the deleted Customer
                        sSrcCustAlias = GetfieldValue("Alias") ' *** Store Customer Alias of the deleted Customer
                        sSrcOwner     = GetfieldValue("Market Type") ' *** Store Ownership of the deleted Customer
                        sSrcWebAdd    = GetfieldValue("Home Page")  ' *** Store internet address of the deleted Customer
                        sSrcLastCon   = GetfieldValue("Last Contacted Date SBC") ' *** Store last Contacted date of the deleted Customer
'           End If
                       
'*****************************************************
'Performing Operations on the Target record
'*****************************************************
            NextSelected

            sTarId       = GetFieldValue("Id")
            sTarAPStatus = GetfieldValue("AP Status SBC")
            sTarAPDate   = GetfieldValue("AP Last Revised SBC")
    sTarPfWFflag = GetFieldValue("Profiled WF SBC")
   
    '*** Set the varibale for allowing delete operation on Source Customer in PreDelete Event
            gsMerge = "Y"                       

    '*** Checking and Setting of AP Status and AP Last Revised
            If sSrcAPDate = "" Then
            Elseif sTarAPDate = "" Then
                SetFieldValue "AP Status SBC", sSrcAPStatus
                SetFieldValue "AP Last Revised SBC", sSrcAPDate
            Elseif DateValue(sSrcAPDate) > DateValue(sTarAPDate) Then
                SetFieldValue "AP Status SBC", sSrcAPStatus
                SetFieldValue "AP Last Revised SBC", sSrcAPDate
            Elseif DateValue(sSrcAPDate) = DateValue(sTarAPDate) And TimeValue(sSrcAPDate) > TimeValue(sTarAPDate) Then
                SetFieldValue "AP Status SBC", sSrcAPStatus
                SetFieldValue "AP Last Revised SBC", sSrcAPDate
            End If
                       
    '*** Settting the field value for workflow to update Profile Flag
            If sTarPfWFflag = "0" OR sTarPfWFflag = "" Then
                        SetFieldValue "Profiled WF SBC", "1"
            End If
           
    '**   Added for Merge using external VB Script. Will not be used for GUI        
'           If TheApplication.getSharedGlobal("gsAppServer") = "N" Then
                        If IsEmpty(GetfieldValue("Main Phone Number")) OR IsNull(GetfieldValue("Main Phone Number")) OR GetfieldValue("Main Phone Number") = "" Then
                                    SetFieldValue "Main Phone Number", sSrcPhone
                        End If
                        If IsEmpty(GetfieldValue("Main Fax Number")) OR IsNull(GetfieldValue("Main Fax Number")) OR GetfieldValue("Main Fax Number") = "" Then
                                    SetFieldValue "Main Fax Number", sSrcFax
                        End If
                        If IsEmpty(GetfieldValue("Alias")) OR IsNull(GetfieldValue("Alias")) OR GetfieldValue("Alias") = "" Then
                                    SetFieldValue "Alias", sSrcCustAlias
                        End If
                        If IsEmpty(GetfieldValue("Market Type")) OR IsNull(GetfieldValue("Market Type")) OR GetfieldValue("Market Type") = "" Then
                                    SetFieldValue "Market Type", sSrcOwner
                        End If
                        If IsEmpty(GetfieldValue("Home Page")) OR IsNull(GetfieldValue("Home Page")) OR GetfieldValue("Home Page") = "" Then
                                    SetFieldValue "Home Page", sSrcWebAdd
                        End If
                        If IsEmpty(GetfieldValue("Last Contacted Date SBC")) OR IsNull(GetfieldValue("Last Contacted Date SBC")) OR GetfieldValue("Last Contacted Date SBC") = "" Then
                                    SetFieldValue "Last Contacted Date SBC", sSrcLastCon
                        End If
'           End If
                                                                                   
End If

Exit Function

ErrorDebug:
            Select Case Err
                        Case 28378
                                    TheApplication.RaiseErrorText Error$
                        Case Else
                                    TheApplication.RaiseErrorText "Error number " & Err & _
                                                " occurred in the " & me.name & _
                                                " BusComp_PreInvokeMethod Event.  " & Error$
            End Select

End Function




Since you do not have access to Siebel Tools, I am sending a document that has the code for Account BC. Please go through this document as much as possible and we can discuss any doubts or issues that you have tomorrow.

Also, we discussed about a requirement in Customers that "Fields Label, HQ Region, HQ State, Region, Federal Parent are read only for Non Prospect customers and also read only for organization other than GLOBAL. GID and HQ Indicator fields are all time read only."
What this means is that fields like Label, HQ Region, Federal Parent etc. will be read-write only when the customer status is Prospect AND the Organization is Global. Both the conditions have to be met in order for these fields to be editable.

Here's how this requirement has been configured:

A calculated field "RO Flag SBC" was created with the calculation: IIF ([Organization] = 'GLOBAL' AND [Status Validation SBC] = 'N', "N", "Y")

Another calculated field "Status Validation SBC" was created with the following calculation: IIF ([Account Status] = 'Active' OR [Account Status] = 'Inactive' OR [Account Status] = 'Non-Horizon', "Y", "N")

BC User Property "Field Read Only Field" was used to make the Federal Parent field dynamically read-write depending upon the Customer Status and Organization.

"Field Read Only Field: Federal Parent SBC" with the value "RO Flag SBC"








No comments:

Post a Comment

Note: Only a member of this blog may post a comment.