I need to auto populate assignment group based on CI changes on the incident
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 09:54 AM
I need to write a client script to auto populate the Assignment Group on the incident form based on the configuration item changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 09:57 AM - edited ‎04-11-2023 09:58 AM
Here's an example of a client script that auto-populates the Assignment Group field on the Incident form based on the Configuration Item field changes:
function onChange(control, oldValue, newValue, isLoading) { if (isLoading || newValue === '') { return; } var ci = g_form.getValue('cmdb_ci'); if (!ci) { return; } var grCI = new GlideRecord('cmdb_ci'); grCI.addQuery('sys_id', ci); grCI.query(); if (grCI.next()) { var assignmentGroup = grCI.getValue('assignment_group'); if (assignmentGroup) { g_form.setValue('assignment_group', assignmentGroup); } } }
In this script, we define a function called onChange that is executed when the cmdb_ci field changes. The function first checks if the field is loading or if the new value is empty. If either of these conditions is true, the function returns without doing anything
Next, we get the value of the cmdb_ci field and use it to query the cmdb_ci table for the corresponding record. If a record is found, we get the value of the assignment_group field from the record. If the assignment_group field is not empty, we set the value of the assignment_group field on the Incident form to the value from the cmdb_ci record.
Note that this script assumes that the cmdb_ci field on the Incident form is a reference field that references the cmdb_ci table, and that the assignment_group field is also a reference field that references the sys_user_group table.
You can add this script to the form's client script section by navigating to the "Client Scripts" related list on the Incident form and clicking the "New" button to create a new client script. Give the script a name, select "onChange" for the type, and paste the script code into the script field.
Save the client script and test it out by changing the value of the cmdb_ci field on the Incident form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-11-2023 10:06 AM
Hi @BHIMA1 ,
We can do that using a Client Callable Script Include and Client Script.
You can write a Client Callable Script Include which can be called using GlideAjax and pass the CI as parameter.
You can run the queries in Script Include and return the sys_id of assignment group.
The client script will set the assignment group.
You can refer the following link for more details on GlideAjax.
https://developer.servicenow.com/dev.do#!/reference/api/tokyo/client/c_GlideAjaxAPI
Let me know if you need more detailed explanation, and let me know your logic to get the group based on CI.
Thanks,
Anvesh
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2024 04:51 AM
here is the answer to your scenario. I have written on change client script on configuration item field on the incident form and wrote script include to get server-side data. make script include as client callable.
script include:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-30-2024 04:56 AM
OOTB there is BR name Auto assigned based on CI /SO , please check , it may be causing issue. @swapnali ombale
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]
****************************************************************************************************************