Adding a signature on worknotes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2011 10:38 AM
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);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2011 10:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2011 12:19 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2011 01:22 PM
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";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-26-2011 01:35 PM
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.