Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

need help in incident management.

Nafisa Zaman
Tera Contributor

Hi all, 

I have a requirement to populate the following fields on the incident form:-
1. In a incident form when a field is checked the choices in section will populate in service now.
2. In a incident form when a field is checked  capture the time in a time filed for any reporting purposes.
3.If a incident state is closed  the choices in section automatically set to be close.
4.if anyone tries to set an incident to resolved while Field  status is open , then throw a message stating "Filed is active , please confirm from team"

 

Any help will be appreciated.

1 ACCEPTED SOLUTION

Aniket Chavan
Tera Sage
Tera Sage

Hello @Nafisa Zaman ,

For the requirements you've listed, most of them can be achieved through client scripts or UI policies:

 

1. Populate choices in a section when a field is checked:
You can use either an onChange or onLoad client script depending on when you need the choices to be populated. For example, in an onChange client script, you could use:

 

if (newValue == true) {
g_form.setSectionDisplay('<section_name>', true);
}

 

Replace `<section_name>` with the actual name of your section.

 

2. Capture time in a field when a checkbox is selected:

You can use the following code in an onChange client script to capture the current date and time and store it in a specific field:

 

if (newValue == true) {
    var today_date = new Date();
    var today_date_time_str = formatDate(today_date, g_user_date_time_format);
    g_form.setValue('time_field', today_date_time_str);
}

 

 

  • Replace 'time_field' with the ID of the field where you want to store the date and time.
  • This will ensure the current date and time is formatted based on the user’s locale settings.

 

 

3. Automatically set choices to "Close" when the incident state is closed:
Use an onChange client script to update the choices when the state is set to "Closed":

if (newValue == 'Closed') {
g_form.setValue('choices_field', 'Close');
}

Replace `'choices_field'` with the field where you need to set the choice.

 

4. Restrict resolution while Field Status is active:
Use an onSubmit client script to check the field status. If it’s active, display an error and prevent submission:

if (g_form.getValue('field_status') == 'Active' && g_form.getValue('incident_state') == 'Resolved') {
g_form.addErrorMessage('Field is active, please confirm from the team.');
return false;
}

Replace `'field_status'` and `'incident_state'` with the appropriate field names.

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket

View solution in original post

3 REPLIES 3

Sid_Takali
Kilo Patron

HI @Nafisa Zaman I suggest you to create a UI Policy as a Best Practice

1. Create onChange client script on Checkbox field. use below code

 

if(newValue == true){
g_form.setSectionDisplay('<section_name>', true);
}

 

OR 

2. you can Create a UI Policy on Condition CheckBox_field is True

Use below code in True Condition in Run Script 

g_form.setSectionDisplay('<section_name>', true);

Use below code in False Condition in Run Script 

g_form.setSectionDisplay('<section_name>', false)

 

 

Sid_Takali
Kilo Patron

Hi @Nafisa Zaman  To capture the time in a time field, You can write a after Insert/Update Business rule

 

if(current.checkbox_field_name.changesTo(true))
              {
              current.time_field_name = gs.nowDateTime();
      }

 

 

Aniket Chavan
Tera Sage
Tera Sage

Hello @Nafisa Zaman ,

For the requirements you've listed, most of them can be achieved through client scripts or UI policies:

 

1. Populate choices in a section when a field is checked:
You can use either an onChange or onLoad client script depending on when you need the choices to be populated. For example, in an onChange client script, you could use:

 

if (newValue == true) {
g_form.setSectionDisplay('<section_name>', true);
}

 

Replace `<section_name>` with the actual name of your section.

 

2. Capture time in a field when a checkbox is selected:

You can use the following code in an onChange client script to capture the current date and time and store it in a specific field:

 

if (newValue == true) {
    var today_date = new Date();
    var today_date_time_str = formatDate(today_date, g_user_date_time_format);
    g_form.setValue('time_field', today_date_time_str);
}

 

 

  • Replace 'time_field' with the ID of the field where you want to store the date and time.
  • This will ensure the current date and time is formatted based on the user’s locale settings.

 

 

3. Automatically set choices to "Close" when the incident state is closed:
Use an onChange client script to update the choices when the state is set to "Closed":

if (newValue == 'Closed') {
g_form.setValue('choices_field', 'Close');
}

Replace `'choices_field'` with the field where you need to set the choice.

 

4. Restrict resolution while Field Status is active:
Use an onSubmit client script to check the field status. If it’s active, display an error and prevent submission:

if (g_form.getValue('field_status') == 'Active' && g_form.getValue('incident_state') == 'Resolved') {
g_form.addErrorMessage('Field is active, please confirm from the team.');
return false;
}

Replace `'field_status'` and `'incident_state'` with the appropriate field names.

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket