- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 01:26 AM
Hello Everyone,
I have a requirement where I need to update the knowledge author to last article updated by that means whoever modified the knowledge article body last.
Need to write a BR for this where I have taken table as Knowledge and in filter condition knowledge base as HR.
Can anyone please help me with the script.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 02:07 AM
Hi @ChanduM ,
You can write a simple Before update business rule as below,
Table: Kb_knowledge
Condition:
Knowledge base is HR
Article body changes
Code:
(function executeRule(current, previous /*null when async*/ ) {
var updatedBy = current.sys_updated_by;
// gs.info('Updated By' + updatedBy);
// gs.info("Author : " + current.author);
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', updatedBy);
gr.query();
if (gr.next()) {
current.author = gr.sys_id;
// gs.info("Author : " + current.author);
}
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 02:07 AM
Hi @ChanduM ,
You can write a simple Before update business rule as below,
Table: Kb_knowledge
Condition:
Knowledge base is HR
Article body changes
Code:
(function executeRule(current, previous /*null when async*/ ) {
var updatedBy = current.sys_updated_by;
// gs.info('Updated By' + updatedBy);
// gs.info("Author : " + current.author);
var gr = new GlideRecord('sys_user');
gr.addQuery('user_name', updatedBy);
gr.query();
if (gr.next()) {
current.author = gr.sys_id;
// gs.info("Author : " + current.author);
}
})(current, previous);
Please mark this comment as Correct Answer/Helpful if it helped you.
Regards,
Swathi Sarang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2024 12:14 AM
Hello Swathi,
It worked!! thank you!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2024 02:29 AM
Hi @ChanduM ,
Your conditions are right. Just add a condition to check if article body changes so you dont beed to trigger BR only if Kbase is HR, Hence there will be 2 conditon check , and in script section go for the below script:
var lastUpdated = current.sys_updated_by;
var grr = new GlideRecord('sys_user');
grr.addQuery('user_name', lastUpdated );
grr.query();
if(grr){
current.author = grr.sys_id;
} //script by sohail khilji
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....