- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 11:47 AM
Good afternoon, in a service added a script for the consultation of a field type reference, where deposit values in that field (email, phone) in a couple of variables (mail, ph).
This script works correctly in ServiceNow.Pero causes a problem with the service portal and does not perform the action.(Shown error: There is a JavaScript error in your browser console) which shows more detail the following error: [SCRIPT:EXEC] Error while running Client Script "Cs:SetPhone": TypeError: Cannot read property 'name' of undefined.
Anyone that can help me?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 11:24 PM
Hi,
Try below code,
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('requested',doThis);
function doThis(caller){
if (isLoading) {
g_form.setValue('email',caller.email);
}
if (newValue != oldValue){
g_form.setValue('email',caller.email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 11:53 AM
The yellow error above that says you need to provide a callback. Are you using g_form.getReference()? If so, try providing it a callback, like g_form.getReference(doThis) and then define a function called doThis(grResponse), where grResponse is the GlideRecord(s) you're processing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 02:55 PM
Hi Tim,
Yes, My script!
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('requested').name;
var Email = g_form.getReference('requested').email;
//g_form.addInfoMessage(Email);
//g_form.addInfoMessage(caller);
if (isLoading) {
g_form.setValue('email',Email);
}
if (newValue != oldValue){
g_form.setValue('email',Email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}
So,
I do not understand in which part to enter the grResponse.could you help me? or give me a clue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2018 11:24 PM
Hi,
Try below code,
function onChange(control, oldValue, newValue, isLoading) {
var caller = g_form.getReference('requested',doThis);
function doThis(caller){
if (isLoading) {
g_form.setValue('email',caller.email);
}
if (newValue != oldValue){
g_form.setValue('email',caller.email);
}
if (newValue == '') {
g_form.setValue('email','');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:52 PM
Hi ,
I am trying to get the user job title based on the user name selected in multirow variable set. Trying below Script Include and client script.. When trying to access the variable set on Service Portal I am getting "There is a JavaScript error in your browser console" error..
Script Include Name : Username_change
var Username_change = Class.create();
Username_change.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
managername_value: function() {
var value = this.request.getParameter("sysparm_id");
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', value);
gr.query();
if (gr.next()) {
var obj = {
//'u_department': gr.getDisplayValue('department'),
//'u_location': gr.getDisplayValue('location'),
//'u_jid': gr.getValue('employee_number'),
//'u_cost_center': gr.getValue('cost_center'),
//'u_manager': gr.getDisplayValue('manager'),
"u_title": gr.getDisplayValue('title'),
// "v_desk_phone_number": gr.getValue("phone"),
};
return JSON.stringify(obj);
}
},
type: 'Username_change'
});
Catalog client script name : GetJobtitleOnchange