Create new Dictionary attribute

NeilH2
Giga Guru

I am looking to create a new dictionary attribute which would be applied to the assigned to field.
When pressed it would insert the name of the person currently viewing the ticket.

I'm having some trouble however locating where the attribute records are kept.

Any pointers?

1 ACCEPTED SOLUTION

Here's a more elegant solution that just uses a small UI Macro and a dictionary attribute:

http://www.servicenowguru.com/system-ui/ui-macros/add-me-ui-macro-user-group-fields/


View solution in original post

13 REPLIES 13

khabibulan72
Kilo Expert

Not sure if I completely understand the requirement, but it sounds like you want to assign a ticket to the person who is currently viewing it. If this is correct, my other guess is that you only want this assignment to occur if there is no one already assigned to the ticket. If all this is true, you may be better off with a client script that fires onLoad and if the assigned_to = "" it will be set to gs.getUserID() . I hope this helps, but sorry if I misunderstood the requirement!


Hi Mike

I want a button next to the assigned to field which when pressed will fill the field with the person viewing. (see attached)

I don't want to use a client script as this is meant as a optional quick way to get your name in the box if your picking up the ticket.


Tom Alday
Mega Guru

Client Script on the Task table:
Type: OnLoad


function onLoad() {

//var el = document.getElementById("incident.assigned_to");

if (g_user.hasRole("itil")) {
//Add a UI macro to a non-reference field

//Set the name of the field in the 'field' variable
var field = "assigned_to";

//Append the table name to get the field id
field = g_form.tableName + "." + field;

try {
//Create the image element and add to the dom
var img = document.createElement('img');
img.src = "yperson.pngx";
img.alt="Assign Incident to Me";
img.title="Assign Incident to Me";
var link = document.createElement('a');
if (navigator.appName == "Microsoft Internet Explorer") {
link.setAttribute('onclick', Function('toMeClick()'));
}
else {
link.setAttribute('onclick', 'toMeClick()');
}

link.name="assign_to_me";
link.id="assign_to_me";
link.appendChild(img);
link.style.display = 'inline';
document.getElementById(field).parentNode.appendChild(link);
}
catch(e) { }
}
}
//onclick event to fire when the image is clicked
function toMeClick(){

var ajax = new GlideAjax('u_AssignUser');
ajax.addParam('sysparm_name','u_assignToUser');
ajax.addParam('sysparm_assignment_group', g_form.getValue('assignment_group'));
ajax.getXML(doSomething);



function doSomething(response){

var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('assigned_to', g_user.userID);
g_form.setValue('assignment_group',answer);
//g_form.setValue('assigned_to', g_user.userID);

}
}

function doSomething(response){

var answer = response.responseXML.documentElement.getAttribute("answer");

}


Hi Tom

I tried your code but couldnt get it to work, am i missing something obvious ?

Created the icon
Created the client script
Icon appears next to field
Click - does nothing

Syntax check of the code says Eval is Evil??