<?xml version="1.0" encoding="UTF-8"?>
<ValidationRule xmlns="http://soap.sforce.com/2006/04/metadata">
    <fullName>AWAL_ValidateScopeOfDeal</fullName>
    <active>true</active>
    <errorConditionFormula>AND(
    RecordType.DeveloperName = &quot;AWAL&quot;,
    NOT($Permission.AWAL_Bypass_VRs),
    NOT(AND(Is_Migrated__c, OR(ISPICKVAL(Migrated_From_Opportunity__r.StageName, "Pass to Approver (KLS only)"), ISPICKVAL(Migrated_From_Opportunity__r.StageName, "Passed to Finance"), ISPICKVAL(Migrated_From_Opportunity__r.StageName, "Passed to BA")))),
    NOT(
        OR(
            ISPICKVAL(StageName, &quot;Deal Tracking&quot;),
            ISPICKVAL(StageName, &quot;Deal Discussions&quot;),
            ISPICKVAL(StageName, &quot;Passed to Finance&quot;),
            ISPICKVAL(StageName, &quot;Passed to Finance Approver&quot;),
            ISPICKVAL(StageName, &quot;Finance Analysis Complete&quot;),

            ISPICKVAL(PRIORVALUE(StageName), &quot;Deal Tracking&quot;),
            ISPICKVAL(PRIORVALUE(StageName), &quot;Deal Discussions&quot;),
            ISPICKVAL(PRIORVALUE(StageName), &quot;Passed to Finance&quot;),
            ISPICKVAL(PRIORVALUE(StageName), &quot;Passed to Finance Approver&quot;),
            ISPICKVAL(PRIORVALUE(StageName), &quot;Finance Analysis Complete&quot;)
        )
    ),
    OR(
        AND(
            ISPICKVAL(MaximumApprovedTerms__r.Scope_of_Deal__c, &quot;Frontline&quot;),
            NOT (
                OR(
                    ISPICKVAL(Scope_of_Deal__c, &quot;Catalogue &amp; Frontline&quot;),
                    ISPICKVAL(Scope_of_Deal__c, &quot;Frontline&quot;)
                )
            )
        ),
        AND(
            ISPICKVAL(MaximumApprovedTerms__r.Scope_of_Deal__c, &quot;Catalogue&quot;),
            NOT (
                OR(
                    ISPICKVAL(Scope_of_Deal__c, &quot;Catalogue &amp; Frontline&quot;),
                    ISPICKVAL(Scope_of_Deal__c, &quot;Catalogue&quot;)
                )
            )
        ),
        AND(
            ISPICKVAL(MaximumApprovedTerms__r.Scope_of_Deal__c, &quot;Catalogue &amp; Frontline&quot;),
            NOT(ISPICKVAL(Scope_of_Deal__c, &quot;Catalogue &amp; Frontline&quot;))
        )
    )
)</errorConditionFormula>
    <errorDisplayField>Scope_of_Deal__c</errorDisplayField>
    <errorMessage>You cannot remove &quot;Frontline&quot;, &quot;Catalogue&quot; or &quot;Catalogue &amp; Frontline&quot; from Scope of Deal if they are part of the Max approved terms.</errorMessage>
</ValidationRule>
