ServiceNow Regex - Close Notes

VijaysaikumarB
Tera Contributor

Hi Everyone,

I have a requirement regarding the incident form. When a user changes the state to "Resolved," the close notes information will be auto populated with the default format below. Users need to update the information after the colon in this format. If the information is not updated/matches the original content, or is left empty after the colon, the action will be aborted.

Could you please help me resolve this issue?

 

Default format for close notes below:

Resolution Steps: 

Step 1

  • Action Taken: [DETAILS OF THE ACTION]
  • Observed Outcome: [WHAT WAS OBSERVED]

Step 2

  • Action Taken: [DETAILS OF THE ACTION]
  • Observed Outcome: [WHAT WAS OBSERVED]

Summary

  • Root Cause Identified: [EXPLAIN THE MAIN CAUSE]
  • Final Resolution: [DESCRIBE THE SOLUTION IMPLEMENTED]
  • Comments or Notes: [ADDITIONAL USEFUL INFORMATION]

Thanks In Advance!!

Rajesh

1 REPLY 1

Viraj Hudlikar
Tera Sage

Hello @VijaysaikumarB 

For auto population of format in Resolution notes you can write a Ui Policy as below:

VirajHudlikar_0-1739026754583.png

VirajHudlikar_1-1739026769291.png

Script :

//Execute if true part
function onCondition() {
 var defaultCloseNotes = "Resolution Steps:\n\nStep 1\n\nAction Taken: [DETAILS OF THE ACTION]\nObserved Outcome: [WHAT WAS OBSERVED]\n\nStep 2\n\nAction Taken: [DETAILS OF THE ACTION]\nObserved Outcome: [WHAT WAS OBSERVED]\n\nSummary\n\nRoot Cause Identified: [EXPLAIN THE MAIN CAUSE]\nFinal Resolution: [DESCRIBE THE SOLUTION IMPLEMENTED]\nComments or Notes: [ADDITIONAL USEFUL INFORMATION]";
        g_form.setValue('close_notes', defaultCloseNotes);
}

//Execute if false part 
function onCondition() {
g_form.clearValue('close_notes');
}


Now once state is set and user is trying to save/update form before submission validation will happen by using a onSubmit client script:

VirajHudlikar_2-1739026902328.png

 

Script :

function onSubmit() {
    //Type appropriate comment here, and begin script below
    if (g_form.getValue('state') == 6) {
        var closeNotes = g_form.getValue('close_notes');
        var defaultCloseNotes = "Resolution Steps:\n\nStep 1\n\nAction Taken: [DETAILS OF THE ACTION]\nObserved Outcome: [WHAT WAS OBSERVED]\n\nStep 2\n\nAction Taken: [DETAILS OF THE ACTION]\nObserved Outcome: [WHAT WAS OBSERVED]\n\nSummary\n\nRoot Cause Identified: [EXPLAIN THE MAIN CAUSE]\nFinal Resolution: [DESCRIBE THE SOLUTION IMPLEMENTED]\nComments or Notes: [ADDITIONAL USEFUL INFORMATION]";

        // Check if the close notes match the default format or if any required fields are empty
        if (closeNotes == defaultCloseNotes ||
            closeNotes.includes('[DETAILS OF THE ACTION]') ||
            closeNotes.includes('[WHAT WAS OBSERVED]') ||
            closeNotes.includes('[EXPLAIN THE MAIN CAUSE]') ||
            closeNotes.includes('[DESCRIBE THE SOLUTION IMPLEMENTED]') ||
            closeNotes.includes('[ADDITIONAL USEFUL INFORMATION]') ||
            closeNotes.match(/Action Taken:\s*$/m) ||
            closeNotes.match(/Observed Outcome:\s*$/m) ||
            closeNotes.match(/Root Cause Identified:\s*$/m) ||
            closeNotes.match(/Final Resolution:\s*$/m) ||
            closeNotes.match(/Comments or Notes:\s*$/m)) {
            alert('Please update the close notes with the required information.');
            return false;
        }
        return true;
    }
}

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.