- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 09:32 AM
Hi,
How would I retrieve Requester email information which is displayed under the float when checking additional information ('i') on a requester in a incident.
It seems to be defined id="sys_readonly.sys_user.email" under the float, is there a way to refer directly to the information like in g_user.userName or is there a way to refer to it some other way? I have tried searching online for solutions but I seem to be hitting a dead end here.
Please let me know if additional information is required or if I'm being unclear
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-30-2017 09:14 AM
OK, thanks.
So, in the incident script:
Type: onLoad
Script:
function onLoad() {
var email = g_form.getReference('caller_id', setEmail);
function setEmail(email) {
if (email)
alert('email is '+ email.email);
g_form.setValue('short_description', email.email); //this changes the short_description, but change it to populate the right field, or remove it if you do not need it.
}
}
For the catalog task, you can use:
Again, an onLoad client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var email = g_form.getReference('request_item.request.requested_for', setEmail);
}
function setEmail(email){
alert('email ' + email.email);
g_form.setValue('short_description', email.email); //this changes the short_description, but change it to populate the right field, or remove it if you do not need it.
}
harel
Edit:
I just noticed that I have the requested for field on my catalog task form. If you don't have it or don't want to add it, you will need to use a GlideAjax call in a client script and a script include:
Client script:
Table: sc_task
Type: onLoad
Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var ri = g_form.getValue('request_item');
var ga = new GlideAjax('getEmail'); //this is the script include
ga.addParam('sysparm_name', 'userEmail'); //this is the function within the script include
ga.addParam('sysparm_ri', ri);
ga.getXML(getResponse);
function getResponse(response) {
var values = response.responseXML.documentElement.getAttribute('answer');
alert(values);
}
}
Script include:
Name: getEmail
Client callable: yes
Script:
var getEmail = Class.create();
getEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
userEmail : function() {
var ri = this.getParameter('sysparm_ri');
var req = new GlideRecord('sc_req_item');
req.addQuery('sys_id', ri);
req.query();
while(req.next()) {
return req.request.requested_for.email;
}
},
type: 'getEmail'
});
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-28-2017 10:01 AM
Hi Alex,
Sometime you are able to dot walk or use a GlideAjax call, depending on your needs.
That depends on what you want to do with it: display the information somewhere, populate a field with it etc.
harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 09:04 AM
Hi Harel,
You seem to have gotten me on the right track. Can these methods be used purely using a client side script? I'm using Tampermonkey so it would have to be purely Client javascript based.
What I would simply need to know is how to fetch the caller email address into a variable so that it can be used in mailto in this case.
As the information is not contained directly in the incident form but I would have to fetch the value possibly based on requested_for(caller) using some type of server call function it seems as I assume there isn't direct way to call on it from the client side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 09:26 AM
Hi Alex,
Here's a little something to get you going. It will retrieve the email address of the requested_for field (change it to your user's field) and insert it into the short description field (again - change it to match your needs):
This is an onChange script running on the requested_for field, but you can change it to be onLoad (let me know if you need my help with that):
Name: get email
Type: onChange
Field: requested_for
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading)
return;
if (newValue == '') {
g_form.setValue('short_description', ''); //if there is nothing in the requested_for field, empty the short description field
return;
}
var email = g_form.getReference('requested_for', setEmail); //get reference is used with reference fields to get a value; use a function to get the value.
}
function setEmail(email) { //this is the function that runs on the variable email
if (email)
g_form.setValue('short_description', email.email); //this sets the email into the short description field
}
If you need more help, let me know.
Harel
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-29-2017 10:58 AM
Function seems to be working and I should be able to run it on load but not sure if it's working.
var email = g_form.getReference('requested_for', setEmail);
Trying to call on email with alert but it gives me undefined? Could it be referencing to a invalid path or is it not referable? full path to sys_user is: sys_display.original.sc_task.request_item.request.requested_for