Monday 18 April 2016

JAVASCRIPT SCENARIO IN MS CRM 2013


Requirement Overview

The Client Budgets entity requires expansion to provide additional budgeting details to be specified optionally alongside a single annual Client Target value.  Individual target values for the 3 main  revenue categories (Hardware, Graphics & Modular) must be optionally available for input against a client record.

The 3 main revenue categories will be combined with the Business Adjustment value to determine the overall annual client target for the give budget year.  The target value shall then be split by month as per the appropriate Budget Phasing record template and entered alongside the existing target value in the Client Stats entity record for each month.

 Solution Brief

1.      Add additional fields to the Client Budgets entity:

Field
Type
Usage/Values
Hardware Target
Money
Holds the budget target value for Hardware sales to the client
Graphics Target
Money
Holds the budget target value for Graphics sales to the client
Modular Target
Money
Holds the budget target value for Modular sales to the client
Categorised Targets
Boolean
Determines whether the annual target is calculated from the 3 categorised targets or entered manually

2.      Amend entry form of the Client Budgets entity to include the new fields
3.      Apply logical flow to the Categorised Targets value
a.       If True:
                                                               i.      Disable “Budgeted Revenue” field
                                                             ii.      Enable “Hardware Target”, “Graphics Target”, “Modular Target”
                                                           iii.      On Save the value of Hardware, Graphics, Modular to be combined and recorded in the “Budgeted Revenue” field
                                                           iv.      On Save the value of the Budgeted Revenue field (post any calculation), to be combined with the “Business adjustment” field and recorded in the “Target” field.
b.      If False
                                                               i.      Enable “Budgeted Revenue” field
                                                             ii.      Disable “Hardware Target”, “Graphics Target”, “Modular Target”
                                                           iii.      On Save the value of Hardware, Graphics, Modular fields to be set to 0.00
                                                           iv.      On Save the value of the Budgeted Revenue field (post any calculation), to be combined with the “Business adjustment” field and recorded in the “Target” field.

4.      Add additional fields to the Client Stats entity:

Field
Type
Usage/Values
Hardware Target
Money
Holds the budget target value for Hardware sales to the client
Graphics Target
Money
Holds the budget target value for Graphic sales to the client
Modular Target
Money
Holds the budget target value for Modular sales to the client

5.      On Save (Create or Update) of the relevant Client Budget record the values of the Hardware Target, Graphics Target and Modular Target fields on the Client Budget record must be assessed. 

The value in these fields must be split using the appropriate Budget Phasing record and each monthly entry in the Client Stats entity updated with the appropriate target value.

e.g.       Client Budget entity –> Hardware Target = £100,000
            Budget Phasing for January = 10%
            Client Stats entity –> Hardware Target for January = £10,000

Hardware target-200 – jan -2
Graphics target- 300-jan - 3
Modular target -400- jan -4

Target revenue -9

The above scenario can be achieved through javascript

OnSave_ClientBudgets = function () {
    
    var categorisedValue = Xrm.Page.data.entity.attributes.get('new_categorisedtargets').getValue();
    if (categorisedValue == true) {
        var totalValue = Xrm.Page.data.entity.attributes.get("new_hardwaretarget").getValue() + Xrm.Page.data.entity.attributes.get("new_graphicstarget").getValue() + Xrm.Page.data.entity.attributes.get("new_modulartarget").getValue();
        Xrm.Page.data.entity.attributes.get("new_budgetedrevenue").setValue(totalValue);
        Xrm.Page.data.entity.attributes.get("new_budgetedrevenue").setSubmitMode("always");


    } else {

        Xrm.Page.getAttribute("new_hardwaretarget").setValue(0);
        Xrm.Page.getAttribute("new_graphicstarget").setValue(0);
        Xrm.Page.getAttribute("new_modulartarget").setValue(0);
        Xrm.Page.data.entity.attributes.get("new_hardwaretarget").setSubmitMode("always");

        Xrm.Page.data.entity.attributes.get("new_graphicstarget").setSubmitMode("always");

        Xrm.Page.data.entity.attributes.get("new_modulartarget").setSubmitMode("always");

    }
}
OnLoad_ClientBudgets = function () {
    CommonDisableEnableField();
}

OnChange_Categorised_Targets = function () {
    
    var categorisedValue = Xrm.Page.data.entity.attributes.get('new_categorisedtargets').getValue();
    if (categorisedValue == true) {

        Xrm.Page.getAttribute("p3dev_budgetedrevenue").setValue(null);
        Xrm.Page.data.entity.attributes.get("p3dev_budgetedrevenue").setSubmitMode("always");


    } else {
        Xrm.Page.getAttribute("new_hardwaretarget").setValue(null);
        Xrm.Page.getAttribute("new_graphicstarget").setValue(null);
        Xrm.Page.getAttribute("new_modulartarget").setValue(null);
        Xrm.Page.data.entity.attributes.get("new_hardwaretarget").setSubmitMode("always");

        Xrm.Page.data.entity.attributes.get("new_graphicstarget").setSubmitMode("always");

        Xrm.Page.data.entity.attributes.get("new_modulartarget").setSubmitMode("always");



    }
    CommonDisableEnableField();
}

CommonDisableEnableField = function () {
    var categorisedValue = Xrm.Page.data.entity.attributes.get('new_categorisedtargets').getValue();
    if (categorisedValue == true) {
        Xrm.Page.getControl("new_budgetedrevenue").setDisabled(true);
        Xrm.Page.getAttribute("new_budgetedrevenue").setRequiredLevel("none");
        Xrm.Page.getControl("new_hardwaretarget").setDisabled(false);
        Xrm.Page.getAttribute("new_hardwaretarget").setRequiredLevel("required");
        Xrm.Page.getControl("new_graphicstarget").setDisabled(false);
        Xrm.Page.getAttribute("new_graphicstarget").setRequiredLevel("required");
        Xrm.Page.getControl("new_modulartarget").setDisabled(false);
        Xrm.Page.getAttribute("new_modulartarget").setRequiredLevel("required");
    } else {
        Xrm.Page.getControl("new_budgetedrevenue").setDisabled(false);
        Xrm.Page.getAttribute("new_budgetedrevenue").setRequiredLevel("required");
        Xrm.Page.getControl("new_hardwaretarget").setDisabled(true);
        Xrm.Page.getAttribute("new_hardwaretarget").setRequiredLevel("none");
        Xrm.Page.getControl("new_graphicstarget").setDisabled(true);
        Xrm.Page.getAttribute("new_graphicstarget").setRequiredLevel("none");
        Xrm.Page.getControl("new_modulartarget").setDisabled(true);
        Xrm.Page.getAttribute("new_modulartarget").setRequiredLevel("none");
    }
}

No comments:

Post a Comment

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