Temporarily circumventing Business Rules to update Work Notes…..

General 1 Comment »
by:

Recently one of our customers requested a data change. A lot of task related tickets needed to be closed. The customer had some checks build in, to prevent unauthorized status changes. These business rules prevented the tasks to be closed by using a script.
Using the setWorkflow(false) method, the business rules were circumvented. By using this method the Worknotes were no longer updated.
Expecting a lot more data fixes we needed to find a solution to add the work notes to the tickets to make sure the tickets had a reference to the change task that ordered the data change.
The following script include was created, we find the script useful and we are happy to share it here with you.

  • Script type: Script Include
  • Name: createNotes
  • Client Callable: TRUE

[cc lang=”javascript”]
var createNotes = Class.create();

createNotes.prototype = {
initialize : function() {
this.user_id = gs.getUserID();
this.user_name = gs.getUserName();
this.user = gs.getUser();
this.update_time = gs.nowDateTime();
this.modCount = 0;
this.domain = “”;
this.table_name = “”;
this.table_sys_id = “”;
this.note = “”;
},
setTableRecord : function(table_name, table_sys_id) {
this.table_name = table_name.toString();
this.table_sys_id = table_sys_id.toString();
},
getTableRecord : function() {
var gr = new GlideRecord(this.table_name);
if(gr.get(this.table_sys_id)) {
this.modCount = gr.sys_mod_count;
this.domain = gr.sys_domain;
return true;
} else {
return false;
}
},
createNote : function(note) {
this.note = note.toString();
// set modCount and domain
var result = this.getTableRecord();
if(result) {
var jfd = new GlideRecord(‘sys_journal_field’);
jfd.initialize();
jfd.name = this.table_name;
jfd.element = “work_notes”;
jfd.element_id = this.table_sys_id;
jfd.value = this.note;
jfd.insert();

var aud = new GlideRecord(‘sys_audit’);
aud.initialize();
aud.tablename = this.table_name;
aud.documentkey = this.table_sys_id;
aud.fieldname = “work_notes”;
aud.user = this.user_id;
aud.record_checkpoint = this.modCount;
aud.oldvalue = “JOURNAL FIELD ADDITION”;
aud.newvalue = this.note;
aud.insert();
var hst = new GlideRecord (‘sys_history_set’);
hst.addQuery(‘id’, this.table_sys_id);
//hst.addQuery(‘table’, this.table_name);

if( this.domain == “global”){
hst.addQuery(‘domain’, “”);
}else{
hst.addQuery(‘domain’, this.domain);
}
hst.query();
if(hst.next()){

var hle = new GlideRecord(‘sys_history_line’);
hle.initialize();
hle.audit_sysid = aud.sys_id;
hle.field = “work_notes”;
hle.set = hst.sys_id;

if (hst.internal_checkpoint == “”){
hle.internal_checkpoint = ‘0’;
} else{
hle.internal_checkpoint = hst.internal_checkpoint;
}
hle.label = “Work notes”;
hle[‘new’] = this.note;
hle.user_id = this.user_name;
hle.user = this.user_id;
hle.user_name = this.user.getFullName();
hle.update_time = this.update_time;
hle.update = this.modCount;
hle.insert();
return true;
}
} else {
return “Error: Wrong table name and/or table sys id”;
}
}
}
[/cc]
How to call this Script Include in a Background Script
[cc lang=”javascript”]
var test = new createNotes();
test.setTableRecord(“task”, ““);
var result = test.createNote(““);
gs.print(result);
[/cc]

If you have question you can reach me via email on .img[at].img.

2nd ServiceNow Benelux User Group meeting in November

General No Comments »
by:


We are proud and enthusiastic to announce the 2nd ServiceNow Benelux User Group meeting and we would like to invite you to join us on this second meeting from many more to come.

Date/time: November 22, 2012 – 08:45am – 13:00
Location: Kromme Schaft 3, 3991 AR Houten, The Netherlands
(hosted by KPN Corporate Market)

Agenda:

08:45 – 09:00 Registration and Coffee
09:00 – 09:05 Welcome by Fred Kouwenberg, Chairman ServiceNow Benelux User Group
09:05 – 09:30 ServiceNow Benelux User Group: Questionnaire results on Organization & Goals
09:30 – 10:15 Creating a Self Service Portal using ServiceNow CMS – by KPN Corporate Market
10:15 – 10:45 ServiceNow Customer Success – Framing the Value
10:45 – 11:00 Coffee break
11:00 – 12:15 3 break-out/round tables session, 25min each, to discuss & share experience on:
– Best Practices Process Models
– Reporting
– Social IT
12:15 – 13:00 Closing – Lunch and opportunity to network

Speakers include:

  • Jacco van Leeuwen (Manager ICTO ServiceNow Support) – KPN Corporate Market
  • Jeff Buckham (Director Customer Success EMEA) – ServiceNow

Registration:

  • Please send us an email on usergroup_BLX@service-now.com if you want to join this 2nd ServiceNow Benelux User Group meeting.
  • Email registration required to account for enough coffee and lunch.
  • ServiceNow business partners can send only 1 participant – the User Group is customer-focused.

Routedescription: Show on Google Maps