Planned start /end date should be editable for admin and Group A in all states

Anupriya_11
Tera Contributor

Hi Team ,

I have a requirement where the Planned Start Date and Planned End Date should be editable in all states for Admin users and members of Group A . For users who are not part of Group A, these fields should be editable only when the record is in the New state on On change form ,.

Could someone please assist with how to achieve this

 

Thank you

9 REPLIES 9

Dr Atul G- LNG
Tera Patron

Hi @Anupriya_11 

Technically, it’s doable. You would need to write a Business Rule (BR) that checks or adds the ACL. But from a financial and process perspective, it’s not correct.

When a change gets approved, the dates should not be modified. If you change the date after approval:

  1. You are bypassing the change confirmation process.
  2. You are disregarding the other approvers who have already approved the change.
  3. You make the reports unstable and biased because the dates have been altered after the fact.

Following the proper flow: if a date needs to be changed, the approver must first reject the change, and then the date can be updated and resubmitted for approval.

*************************************************************************************************************
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/dratulgrover [ Connect for 1-1 Session]

****************************************************************************************************************

Could you possibly explain your approach, @Dr Atul G- LNG? How can a BR check or add ACL? 

_____
Answers generated by GlideFather. Check for accuracy.

Tanushree Maiti
Kilo Patron

Hi @Anupriya_11 

 

Option1: a. Create a Write ACL  on Planned Start Date[start_date]

 

  • Navigate to System Security > Access Control (ACL) and click New.
  • Operation: write
  • Name:change_request and select Planned Start Date[start_date] from the field dropdown.
  • ACL Script:
    answer = checkEditable();
    
    function checkEditable() {
           if (gs.hasRole('admin')) 
    {
    return true; }
    if (gs.getUser().isMemberOf('Group A')) { // Replace 'Group A' with group's Sys ID return true; } if (current.state == -5) //assuming -5 is new state
    {
    return true; } return false; }

   b. Repeat the process for i.e Create a Write ACL  on Planned End Date[end_date]

 

Option2: Using UI policy ,Ui policy action and ui policy script - it can be done.

 

Option3 .

a.Create a Display Business rule to check  if the user is in Group A or has the Admin role

 

Sample code:

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

g_scratchpad.isGroupA = gs.getUser().isMemberOf('Group A') || gs.hasRole('admin');

})(current, previous);

 

b.  Using scratchpad variable to determine if the fields should be locked . Write a onLoad Client script

function onLoad() {

 

if (g_scratchpad.isGroupA)

{

return;

}

var state = g_form.getValue('state');

if (state != '-5') { // '-5' is the OOB 'New' state

g_form.setReadOnly('start_date', true);

g_form.setReadOnly('end_date', true);

 

}

}

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

ChallaR
Giga Guru

HI @Anupriya_11 ,

please find the below recommended script -

Business Rule (Before Update)

  • When: before update
  • Condition: leave empty (handled in script)
(function executeRule(current, previous /*null when async*/) {

    var isAdmin = gs.hasRole('admin');
    var isGroupA = gs.getUser().isMemberOf('Group A');

    // If user is NOT admin and NOT in Group A
    if (!(isAdmin || isGroupA)) {

        // Allow editing only when state is New
        if (current.state != 'new') {

            if (current.planned_start_date.changes() || current.planned_end_date.changes()) {
                gs.addErrorMessage('You can edit Planned Start Date and End Date only in New state.');
                current.setAbortAction(true);
            }

        }
    }

})(current, previous);
  • NOTE -
  • Make sure "Group A" is the exact group name
  • Confirm that 'new' is the actual state value (sometimes it might be 1 instead of 'new' depending on your setup)

Thanks,

Rithika.ch