Automation for ServiceNow community

keithtan
Tera Guru

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!

8 REPLIES 8

Thanks for sharing that. Are you able to access that table using the Khoros Community API?

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.

// 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);
  }
}

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