Automation for ServiceNow community
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2024 07:18 AM
Hi, I would like to create a automated way for community questions to be assigned to a user with a particular role if the question is unanswered after x number of days.
I have looked into community configurations and any APIs for community, but I have not found any way to do that yet.
Any one knows if there is a way to do it?
Thank you!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2024 08:39 AM
Thanks for sharing that. Are you able to access that table using the Khoros Community API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 11:02 PM - edited 04-04-2024 11:03 PM
This is the script that will be put into a scheduled job that runs daily:
// retrieve all questions with 0 answers
var target = new GlideRecord('kb_social_qa_question');
target.addQuery('answer_count', 0);
target.query();
while (target.next()) {
// find time difference in days between created date and today's date
var gdt = new GlideDateTime();
var createdDate = target.sys_created_on.dateNumericValue();
var currDate = gdt.getNumericValue();
gs.info('created: ' + createdDate + ', today: ' + currDate);
var timeDiff = currDate - createdDate;
var daysDiff = timeDiff / 24 / 60 / 60 / 1000;
gs.info('Diff: ' + daysDiff);
// fill Assigned to field
if (daysDiff >= 3 && target.u_assigned_to == '') {
// get consultant
var liveProfileRef = new GlideRecord('live_profile');
liveProfileRef.addQuery('name', 'Keith Tan');
liveProfileRef.setLimit(1);
liveProfileRef.query();
liveProfileRef.next()
gs.info(liveProfileRef.getValue('name'));
target.u_assigned_to = liveProfileRef.sys_id;
target.update();
gs.info('Assigned to: ' + target.u_assigned_to);
}
}
Feel free to suggest any improvement to what I am doing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 11:04 PM
// retrieve all questions with 0 answers
var target = new GlideRecord('kb_social_qa_question');
target.addQuery('answer_count', 0);
target.query();
while (target.next()) {
// find time difference in days between created date and today's date
var gdt = new GlideDateTime();
var createdDate = target.sys_created_on.dateNumericValue();
var currDate = gdt.getNumericValue();
gs.info('created: ' + createdDate + ', today: ' + currDate);
var timeDiff = currDate - createdDate;
var daysDiff = timeDiff / 24 / 60 / 60 / 1000;
gs.info('Diff: ' + daysDiff);
// fill Assigned to field
if (daysDiff >= 3 && target.u_assigned_to == '') {
// get consultant
var liveProfileRef = new GlideRecord('live_profile');
liveProfileRef.addQuery('name', 'Keith Tan');
liveProfileRef.setLimit(1);
liveProfileRef.query();
liveProfileRef.next()
gs.info(liveProfileRef.getValue('name'));
target.u_assigned_to = liveProfileRef.sys_id;
target.update();
gs.info('Assigned to: ' + target.u_assigned_to);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2024 11:06 PM
For some reason, the reply does not work if I paste the script into a code sample.
This is the script that will be put in a scheduled job that runs daily:
// retrieve all questions with 0 answers
var target = new GlideRecord('kb_social_qa_question');
target.addQuery('answer_count', 0);
target.query();
while (target.next()) {
// find time difference in days between created date and today's date
var gdt = new GlideDateTime();
var createdDate = target.sys_created_on.dateNumericValue();
var currDate = gdt.getNumericValue();
gs.info('created: ' + createdDate + ', today: ' + currDate);
var timeDiff = currDate - createdDate;
var daysDiff = timeDiff / 24 / 60 / 60 / 1000;
gs.info('Diff: ' + daysDiff);
// fill Assigned to field
if (daysDiff >= 3 && target.u_assigned_to == '') {
// get consultant
var liveProfileRef = new GlideRecord('live_profile');
liveProfileRef.addQuery('name', 'Keith Tan');
liveProfileRef.setLimit(1);
liveProfileRef.query();
liveProfileRef.next()
gs.info(liveProfileRef.getValue('name'));
target.u_assigned_to = liveProfileRef.sys_id;
target.update();
gs.info('Assigned to: ' + target.u_assigned_to);
}
}
Feel free to suggest any improvements