Adding a signature on worknotes

gaidem
ServiceNow Employee
ServiceNow Employee

So I had a user ask me about having an automatic signature added on work notes.

I created a signature field on the user record. Then I created a client script(may not be perfect, but it works):



function onLoad() {
//Add a UI macro to a non-reference field
//Set the name of the field in the 'field' variable
var field = document.getElementById('label.incident.work_notes');
//document.getElementById('lablel.incident.work_notes.make_spacing_ok').style.display='none';

try{
//Create the image element and add to the dom
var img = document.createElement('img');
img.src = "images/icons/scripts.gifx";
img.alt="Add Signature";
img.title="Add Signature";
var link = document.createElement('a');
if (navigator.appName == "Microsoft Internet Explorer"){
link.setAttribute('onclick', Function('doSomething()'));

}
else{
link.setAttribute('onclick', 'doSomething()');
}
link.name="signatures";
link.id="signature";
link.appendChild(img);
//field.parentNode.appendChild(link);
field.appendChild(link);
}
catch(e){
//alert('Error');
}
}

//onclick event to fire when the image is clicked
function doSomething() {
var userID = g_user.userID;
var signature ='';
var curNotes = g_form.getValue('work_notes');
var userRec = new GlideRecord('sys_user');
userRec.addQuery('sys_id',userID);
userRec.query();
if(userRec.next()){
signature = userRec.u_signature
}
var signature2='';
signature2 += curNotes+'\n'+'\n'+signature;

g_form.setValue('work_notes',signature2);
}

5 REPLIES 5

gaidem
ServiceNow Employee
ServiceNow Employee

Screen Shots


john_roberts
Mega Guru

There's a couple options to eliminate the need for a server call to get mostly static data from the user record.
1. Get the user signature with a display business rule so the client script has direct access to it.
2. Store the user signature in session client data and you'll have access to it from any form.


gaidem
ServiceNow Employee
ServiceNow Employee

Thanks John. For the business rule solution, I have never had luck calling functions from CS's. It always returns null

As a basic test example I did this:

Client Script
On Load
function onLoad() {
//Type appropriate comment here, and begin script below
var script = "returntest()";
var answer = AJAXEvaluateSynchronously(script);
alert(answer);
}

Business Rule
Global
Client Callable

function returntest(){
return "hi";
}


The display type business rules that I linked to are not called from the client, they load data pre-display and pass to the client with the form.