How to prevent past date selection on a GRC Control Attestation metric field?

Sachin G K1
Kilo Sage
Hi everyone,
 
I am working with GRC / IRM Control Attestations. I have added a custom question/metric of type Date called "Target Date".
I need to enforce a validation rule that prevents users from selecting a past date when completing the attestation. If they select a past date, it should clear the field and show an error message.
 
Can anyone suggest how to implement it?
 
SachinGK1_0-1790798168330.png



Thanks in Advance!!

 
1 ACCEPTED SOLUTION

RaghavendraGund
Tera Guru

Hello @Sachin G K1 

I Replicated this in my PDI by adding a Date Question "Target Date" just to match your Screenshot.(Refer Screenshot1)
What I found:
1. The designer has no date Validation: A Date question's Properties are only Name, Question, Active, Mandatory and Details. No script field to write Validations (Refer Screenshot2)

2. I first tried a before-rule on asmt_assessment_instance_question that aborts when the date is in the past. The error message appears, but the attestation still completes, with the mandatory Target Date left empty. The take page enforces Mandatory only in the browser, and the submit doesn't re-check it on the server.

The Approach that worked for me:
A before-update Business rule on asmt_assessment_instance
Refer Screenshots for Business rule(Screenshot3 & Screenshot4)

  • When: before, Update
  • Filter: State changes to Complete AND Metric type is your attestation metric type

(function executeRule(current, previous) {
var q = new GlideRecord('asmt_assessment_instance_question');
q.addQuery('instance', current.getUniqueValue());
q.addQuery('metric', '<sys_id of your Target Date metric>');
q.query();
if (!q.next())
return;

var picked = q.getValue('string_value'); // stored as yyyy-MM-dd
var today = new GlideDateTime().getLocalDate().getValue(); // yyyy-MM-dd, user's time zone

if (!picked || picked < today) {
gs.addErrorMessage('Target Date cannot be empty or in the past. Please update it and submit again.');
current.setAbortAction(true);
}
})(current, previous);

Test Results in my PDI:
-->I picked a CTRL0010011 Record in PDI(Refer Screenshot5)
-->Clicked on "Attest" UI Action. which created a Classic Attestation(Refer Screenshot6)
--> impersonate as "Patty" Attestation Responder and open the assessment instance and fill the target as past date(Refer screenhot7 & screenshot8)
---> Now end impersonation and go to the CTRL0010011 Record, check that the Assessment instance state is still "Ready to take" not complete(Refer screenshot9) ---> This proves that our business rule worked

---> if you want to test the other way around, select the future date and you can notice that Assessment state will be in complete state.


One limitation: after a blocked submit, the thanks page shows the error and "You have completed this attestation." The record isn't completed, but the message is misleading, so it's worth telling attesters about.

Clearing the field in the browser, as you described, would mean customizing the assessment_take2 UI page. I haven't tested that. Because it's a platform page, it would add upgrade risk, so I'd treat the server-side rule as the enforcement either way.

If my reply helped, please mark it as Helpful and Accept as Solution

Regards
Raghavendra G




















View solution in original post

2 REPLIES 2

RaghavendraGund
Tera Guru

Hello @Sachin G K1 

I Replicated this in my PDI by adding a Date Question "Target Date" just to match your Screenshot.(Refer Screenshot1)
What I found:
1. The designer has no date Validation: A Date question's Properties are only Name, Question, Active, Mandatory and Details. No script field to write Validations (Refer Screenshot2)

2. I first tried a before-rule on asmt_assessment_instance_question that aborts when the date is in the past. The error message appears, but the attestation still completes, with the mandatory Target Date left empty. The take page enforces Mandatory only in the browser, and the submit doesn't re-check it on the server.

The Approach that worked for me:
A before-update Business rule on asmt_assessment_instance
Refer Screenshots for Business rule(Screenshot3 & Screenshot4)

  • When: before, Update
  • Filter: State changes to Complete AND Metric type is your attestation metric type

(function executeRule(current, previous) {
var q = new GlideRecord('asmt_assessment_instance_question');
q.addQuery('instance', current.getUniqueValue());
q.addQuery('metric', '<sys_id of your Target Date metric>');
q.query();
if (!q.next())
return;

var picked = q.getValue('string_value'); // stored as yyyy-MM-dd
var today = new GlideDateTime().getLocalDate().getValue(); // yyyy-MM-dd, user's time zone

if (!picked || picked < today) {
gs.addErrorMessage('Target Date cannot be empty or in the past. Please update it and submit again.');
current.setAbortAction(true);
}
})(current, previous);

Test Results in my PDI:
-->I picked a CTRL0010011 Record in PDI(Refer Screenshot5)
-->Clicked on "Attest" UI Action. which created a Classic Attestation(Refer Screenshot6)
--> impersonate as "Patty" Attestation Responder and open the assessment instance and fill the target as past date(Refer screenhot7 & screenshot8)
---> Now end impersonation and go to the CTRL0010011 Record, check that the Assessment instance state is still "Ready to take" not complete(Refer screenshot9) ---> This proves that our business rule worked

---> if you want to test the other way around, select the future date and you can notice that Assessment state will be in complete state.


One limitation: after a blocked submit, the thanks page shows the error and "You have completed this attestation." The record isn't completed, but the message is misleading, so it's worth telling attesters about.

Clearing the field in the browser, as you described, would mean customizing the assessment_take2 UI page. I haven't tested that. Because it's a platform page, it would add upgrade risk, so I'd treat the server-side rule as the enforcement either way.

If my reply helped, please mark it as Helpful and Accept as Solution

Regards
Raghavendra G




















yashkamde
Giga Sage

Hello @Sachin G K1 ,

 

OOTB metrics also have no client-side validation for the Date data type.

 

What might works a before Business Rule on the answer record as user's answer is saved to asmt_assessment_instance_question, so validate there.

 

Create a BR :

Table: Assessment Instance Question (asmt_assessment_instance_question)

When: before, Insert + Update

Filter condition: Metric is Target Date

 

Script :

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var val = current.getValue('string_value');
    if (!val) return;

    var picked = new GlideDate();
    picked.setDisplayValue(val); // answer is stored in the user's date format
    var today = new GlideDate(); // today's date

    if (picked.getNumericValue() < today.getNumericValue()) {
        current.string_value = '';
        current.value = '';
        gs.addErrorMessage('Target Date cannot be in the past. Please select today or a future date.');
		//current.setAbortAction(true);
    }

})(current, previous);

 

So got this when tested:

Screenshot 2026-10-01 115200.png

 

The Assessment gets submits but the value does not stored in answer table :

Screenshot 2026-10-01 115307.png

 

While submitting :

Screenshot 2026-10-01 115605.png

 

If my response helped mark as helpful and accept the solution.