Calculation from Value-List in Archer GRC based on date (with non-empty validation)

2.5k Views Asked by At

I've been trying to implement what's been asked in this Stack Overflow question, here:

Calculation for status in Archer GRC based on date

Trying to create a status field based on a number of Value Lists that users select from, but a request has been made that we check a date field for a value to ensure an estimated date has been set so that the calculation can determine if the status of the record is "In Progress", "Late" or "Not Started".

...and now, I have a requirement for an actual popup warning message of some sort to prompt the user to make sure the date field is not blank.

How would I add this functionality?

1

There are 1 best solutions below

2
On BEST ANSWER

In order to deliver the functionality you are looking for you have to use a "Custom Object". It is an object you put on the layout of the application in Archer that contains JavaScript code. This code will be executed as soon as the form of the application is loaded. There is a special type of the field "Custom Object" available in the Layout editor for each application in the Application Builder in Archer.

Note - I don't recommend to use custom objects in general and neither RSA Support. Every time you modify the layout in the given application, you have retest and sometimes correct IDs for your custom object. You can write an ID independent custom object and use field names, but in this case custom object will have more code. I prefer to make custom objects as short as possible.

Your custom object should do the following:

  1. Override the behavior of the "Save" and "Apply" button in the top tool bar available for every application form in Archer.
  2. Once "Save" and "Apply" buttons are "overwritten", every time they are clicked on your function will be called. So you need to create a click handler function.
  3. Your click handler function will check values user is required to populate and will either return warning, or will call the original handler for "Save/Apply" buttons.

This is a code template you can start with:

<script type="text/javascript">
// ids are used to locate buttons
var buttons_ids = [
    "master_btnSave",   //  "Save" button ID
    "master_btnApply"   //  "Apply" button ID
];
// parameters are used in the "onclick" default handlers to call original handlers
var buttons_parameters = [
    "master$btnSave",   //  "Save" parameter
    "master$btnApply"   //  "Apply" parameter
];

document.getElementById(buttons_ids[0]).onclick = function(){   Validator_of_required_fields(buttons_parameters[0])};
document.getElementById(buttons_ids[1]).onclick = function(){   Validator_of_required_fields(buttons_parameters[1])};
// end of the script body

//==== Validator function attached to Save and Apply buttons
function Validator_of_required_fields(parameter){
    // ids of the input fields to validate
    var inputs_to_validate_ip_address = [ "master_DefaultContent_rts_XXX_YYY_t" ];

    // jQuery selector is used here. Archer v5.x has jQuery library loaded by default
    // you will need to modify this selector
    var field_value = $('#'+inputs_to_validate_ip_address[0]+':first').val();

    if(field_value.length = 0) {
        // Here you are calling Archer Warning function
        var msg = "[Text to display to user]";
        var title = 'Required Field';
        WarningAlert(msg,title);
        return false;
    };

    // default onclick processor
    ShowAnimationAndPostback(parameter);
    return false;
};

Some comments on this code:

  • You will need to modify the validation function to work with values stored in the fields you need.
  • I used a rather 'unusual' way to override the behavior of the "Save" and "Apply" buttons using the following code:
    document.getElementById(buttons_ids[0]).onclick = function(){ bla, bla, bla }
    There are simpler way to do the same, but this way custom object works fine in IE8-11, FF, Chrome and Opera. Let me know if you find a simpler way to override buttons that is browser agnostic.
  • Function WarningAlert(msg,title); is a build-in Archer warning message function. It worked fine in Archer v5.4. You might need to use simple JavaScript Alert function if WarningAlert doesn't work in your version of Archer.
  • Note that behavior of the "Save" and "Apply" buttons might be overwritten back to default in case if user opens up any pop-up dialog windows to populate a value list or cross-reference field. If that is the case, you will have to wrap the code provided into another function and attach it to the OnLoadWindow event (or similar).
  • I try to avoid using any JavaScript libraries in my custom objects. This way it is simpler to support them and you have less dependencies. I used jQuery in the provided example only because Archer already uses this library once the page is loaded.

Flak, make sure to test your custom object very well and good luck!