- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 02:27 AM - edited 01-22-2024 02:28 AM
I'm using a common field on both Incident form and incident task form,
on incident form i have written an on change client script to make the work notes mandatory whenever this fields value changes.
but in order achieve the same on incident task form im not able write an on change client script for this field as its originally created on incident table and not on the incident task.
How can i achieve this
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 02:57 AM
Hi @Yash38
What i understood is, you writing CS on Incident table but you want to apply the same in Incident task as well? If this is this the case It will NOT work. bcz worknotes on Inc and Inc task are extending from Task tables , so if your write CS on Task table then it will work for Inc task but it wil be global change and may impact other modules atleast change and Prb.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
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/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 06:47 AM - edited 01-23-2024 02:03 AM
If I understand you correctly, you have a dot walked field from incident on incident task. And when a user makes a change to the dot walked field on the incident task record, you want the work notes to be mandatory on incident task.If this is correct, then you cannot track client side changes on the dot walked field on Incident Task. You can use UI policy and in the filter conditions dot walk to the incident field, but again, you cannot track if that field has changed before updating the record.
- One solution will be to have the field created on the task table and track the changes there.
- The second solution, create a new field on the Incident task and then sync it with the corresponding field on the Incident. You can then run the Client script or UI policy on the Incident task table.
- The Third solution (quite custom), create a display business rule and save the dot-walked value in a scratchpad variable. Then create an onSubmit client script, and validate if the form value has changed by comparing it to the scratchpad value. If the value has changed, then you can prompt the user to add a worknote. Once filled in, you can update the form value as required.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 02:37 AM
To achieve this, you can use a Business Rule instead of a Client Script. A Business Rule can be applied to multiple tables, including extended tables like the Incident Task table. Here are the steps:
1. Navigate to System Definition > Business Rules.
2. Click on New to create a new Business Rule.
3. Give your Business Rule a name, for example, "Make Work Notes Mandatory".
4. In the "When to run" section, select "After" and "Update".
5. In the "Table" field, select "Task [task]". This will apply the Business Rule to all task-based tables, including Incident and Incident Task.
6. In the "Condition" field, write a condition to check if the common field has changed. You can use the "changes()" function for this. For example, if your common field is called "common_field", your condition would be "current.common_field.changes()".
7. In the "Script" field, write a script to make the work notes mandatory. You can use the "setMandatory()" function for this. Here is a sample script:
javascript
if (current.work_notes.nil()) {
gs.addErrorMessage('Work notes are mandatory when the common field changes.');
current.setAbortAction(true);
}
8. Click on Submit to save your Business Rule.
This Business Rule will now run whenever the common field changes on either the Incident form or the Incident Task form, and it will make the work notes mandatory.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 03:08 AM - edited 01-22-2024 03:08 AM
Hi @Rajdeep Ganguly , i tried the script you provided, It gives info message and does not save the record if i do not give work notes but at the same time if I give work notes and change the field value it will again give info message and will save the record with the work notes but field values will not get updated to new values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2024 01:22 AM
It seems like you're experiencing an issue with a script in ServiceNow that is not updating field values as expected. Here's a general approach to troubleshoot and resolve this issue:
1. Check the Order of Operations: ServiceNow follows a specific order of operations when executing scripts and business rules. Make sure your script is not being overridden by another script or business rule.
2. Validate the Script: Ensure that your script is correctly referencing the field you want to update. Check for any syntax errors or incorrect field names.
3. Use GlideRecord: If you're not already, consider using GlideRecord to update field values. GlideRecord is a ServiceNow API that allows you to query, update, and delete records in your instance.
4. Debugging: Use the ServiceNow debugging feature to trace the execution of your script. This can help identify where the script is failing to update the field values.
5. Use gs.addInfoMessage: This function can be used to display informational messages to the user. You can use this to confirm if your script is being executed as expected.
Here's a sample script using GlideRecord to update a field:
javascript
var gr = new GlideRecord('table_name');
gr.get('sys_id');
gr.field_name = 'new_value';
gr.update();
Remember to replace 'table_name', 'sys_id', 'field_name', and 'new_value' with your specific details.
6. Test: After making any changes, remember to thoroughly test your script to ensure it's working as expected.
Remember, without the specific details of your script and the field you're trying to update, this is a general approach. You may need to adjust this based on your specific situation.
nowKB.com
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - https://nowgpt.ai/
For the ServiceNow Certified System Administrator exams try this :
https://www.udemy.com/course/servicenow-csa-admin-certification-exam-2023/?couponCode=NOW-DEVELOPER
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2024 02:38 AM
Which field are you talking about?
Both the tables extend from Task. So if you want one Client script on a field that is extended from the task table, you will have to write the client script on the task table (and make inherited active). But please keep in mind that doing so will mean that the script will execute on all tables extended from Task. So as a precaution, a check on the table name (either incident or incident task) is recommended in the script.