Service Catalog: Record Producer Variables in your Change Ticket

General 2 Comments »
by:

At a recent project, we had a requirement to show the variables of a record producer on the change record that was created by the record producer. This can be done easily by adding the variable editor to the form.

However… the UI Policies and client scripts defined on the record producer cannot run on the produced record like you can do with Request Item variables.

The Challenge
The requirement of the client was to make the information of the variables available on the change record. Having the fields listed out in a change specific field was the next option the Client had for this requirement. The variables however needed to be listed in the same order as they appear on the record producer form. The functionality of a label and multiple checkboxes is used regularly, this should be visualized the same way in the record producer.

Another reason why the variable pool option did not make it was because the variable pool can only be used to get the label,value and type of a variable related to the change record. We needed more information from the variable, for example the order field.
Continue reading…»

Using a SOAP button on a Request Item

General No Comments »
by:

For a client we build a button in a service request which supposed to integrate with a soap StefanSoap1484request. The client didn’t want the Soap Call to be happening on the change of a field but wanted the user to choose it actively trough a button.
Continue reading…»

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.

Unexpected behavior using ServiceNow Domain functionality

General No Comments »
by:

We have a client that stretches the possibilities of the ServiceNow domain separation to the max.
In this article I would like to share an example of something that didn’t go as expected….

The domain structure:

 

 

 

 

 

 

 

 

Continue reading…»

Organize your catalog variables in an e-mail using HTML

General 2 Comments »
by:

Catalog variables can be placed in an email notification by scripting. This is easy.
Placing the variables in a nice table is more difficult, a little html knowledge is required.

Building the html code has to be done by using the template.print(”); functionality.

Normally you would build a table like this:

<mail_script>

template.print(‘ <table border = “1”>’);

template.print(‘<tr><td>Field</td> <td>Value</td></tr>’);

template.print(‘<tr><td> UserName</td><td>stefan</td>’);

template.print(‘<tr><td> Phone</td><td>0612345678</td></tr>’);

template.print(‘</table>’);

</mail_script>

However, Service-now wants to end the table as fast as possible and finds an end of a row (</tr>) often a good place to end the table.
Also Service-now can find the end of a table cell </td> a possibility to end the table.
A simple script like this will probably go alright, but when there is other code between the ‘template.
Print’ actions, the system adds code automatically, this will change the script with errors as a result.
Continue reading…»