Fields populated when kb article is present
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 12:15 AM
Hi,
I have one requirement actually..!!! They gave some of the fields that needs to be populated when the kb article is attached to an incident.
And also they mentioned that the criteria for already existing values in those fields and later if kb is attached it will remain as it is for all the fields. What is the way you suggest?
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 12:43 AM
Hi @Community Alums ,
You can write BR to achieve this, below is the sample code:
(function executeRule(current, previous /*null when async*/) {
// Check if the Knowledge Base field is updated
if (current.kb_article) {
// Update other fields only if they are empty (not already populated)
if (gs.nil(current.field1)) {
current.field1 = "New Value for Field 1";
}
if (gs.nil(current.field2)) {
current.field2 = "New Value for Field 2";
}
// Repeat this pattern for other fields
}
})(current, previous);
Thanks,
Ratnakar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-08-2023 01:33 AM
Hi @Community Alums
Check Knowledge Property:
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
12-08-2023 01:53 AM
Hi @Community Alums ,
Have a nice day!
You can achieve this requirement using an after-business rule on the m2m_kb_task table which will run on the insert/update. This table stores the relationship between incidents and attached KB articles.
In advance view, write a script to
- Identify the attached KB article by querying the kb_knowledge table using the kb_knowledge.sys_id field from the m2m_kb_task record.
- Extract the desired values from the KB article using its corresponding fields.
- You can write a conditional statement to check if the target fields in the incident table record are already populated.
- If the field is empty, update it with the extracted value from the KB article.
- If the field already has a value, leave it untouched.
- Use the GlideRecord API to efficiently access and update the incident and KB article records.
Here is the sample script:
(function executeRule(current, previous) {
var incidentId = current.task; // Get the incident ID from m2m_kb_task record
var kbArticleId = current.kb_knowledge; // Get the KB article ID from m2m_kb_task record
var kb_article = new GlideRecord('kb_knowledge');
kb_article.addQuery('sys_id', kbArticleId);
kb_article.query();
if (kb_article.next()) {
// Check if the target fields in the incident table record are already populated.
//Create object incident_gr using GlideRecord with condition ('sys_id=',incidentId)
if (incident_gr.field_name == '') {
// Update the field with the extracted value from the KB article
incident_gr.field_name = kb_article.field_name;
}
}
}
Modify the script with the correct backend names and conditions.
Please mark it 'helpful' and 'accept it as a solution' if this helps you in any way!
Thanks,
Prasad