TypeError: id is undefined

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2016 12:08 PM
This is a variable set, when I fill in requested for field all other fields get populated. It does populate but shows an error at the end "TypeError: id is undefined". When I close the error window, all the populated fields are wiped out and looks like below. this is happening after Geneva upgrade. Working good in Fuji.
Using: Script Include - u_ajaxGetUserInfo
Anyone faced this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2016 12:18 PM
Hi Rajini,
Might be to do with id of the read only fields. It is changed once it is readonly. If you are using $ selector that could be a reason for the error.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2016 12:42 PM
This is the only script.
-----------------------------------------------------------------------------------
/* Script Include: u_ajaxGetUserInfo. Jim Fease - ServiceNow */
var u_ajaxGetUserInfo = Class.create();
u_ajaxGetUserInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getUserRecord: function() {
var result = this.newItem("result");
var search_field = this.getParameter('search_field');
var search_value = this.getParameter('search_value');
var grUser = new GlideRecord('sys_user');
grUser.addQuery(search_field, search_value);
grUser.query();
if (grUser.next()) {
result.setAttribute('sys_id', grUser.sys_id);
result.setAttribute('name', grUser.name);
result.setAttribute('employee_number', grUser.employee_number);
result.setAttribute('user_name', grUser.user_name);
result.setAttribute('first_name', grUser.first_name);
result.setAttribute('middle_name', grUser.middle_name);
result.setAttribute('last_name', grUser.last_name);
result.setAttribute('company', grUser.company);
result.setAttribute('companyDisplay', grUser.company.getDisplayValue());
result.setAttribute('cost_center', grUser.cost_center);
result.setAttribute('cost_centerDisplay', grUser.cost_center.getDisplayValue());
result.setAttribute('department', grUser.department);
result.setAttribute('departmentDisplay', grUser.department.getDisplayValue());
result.setAttribute('email', grUser.email);
result.setAttribute('title', grUser.title);
result.setAttribute('manager', grUser.manager);
result.setAttribute('managerDisplay', grUser.manager.getDisplayValue());
result.setAttribute('vip', grUser.vip);
result.setAttribute('mobile_phone', grUser.mobile_phone);
result.setAttribute('business_phone', grUser.phone);
result.setAttribute('location', grUser.location);
result.setAttribute('locationDisplay', grUser.location.getDisplayValue());
result.setAttribute('street', grUser.street);
result.setAttribute('city', grUser.city);
result.setAttribute('state', grUser.state);
result.setAttribute('zip', grUser.zip);
result.setAttribute('country', grUser.country);
// User defined fields
result.setAttribute('objectguid', grUser.u_objectguid);
// calculated fields
// Calclulate country they live in
var company = grUser.company.getDisplayValue();
company = company.toUpperCase();
var calc_country = "us";
if ((company.indexOf("UK") > -1) ||
(company.indexOf("ABC UK") > -1) ||
(company.indexOf("ABC-UK") > -1) ||
(company.indexOf("ABC LTD") > -1) ||
(company.indexOf("ABC ITS") > -1)){
calc_country = "uk";
}
if (company.indexOf("ABC MAU") > -1){
calc_country = "mauritius";
}
if ((company.indexOf("CANADA") > -1) ||
(grUser.email.indexOf("@ABC.ca") > -1)){
calc_country = "canada";
}
result.setAttribute('calc_country', calc_country);
// Employee type employee, contractor, service, undetermined.
var empType = 'undetermined';
if (grUser.ldap_server.getDisplayValue() == 'LDAP Server Canada'){
// for Canada, we are to use company.
if ((company == "ABC CORPORATION") || (company == "ABC CANADA") || (company == "MAURITIUS")){
empType = 'employee';
} else {
if (company != ''){
empType = 'contractor';
} // else leave as undetermined
}
// End of Canada
} else {
if (grUser.ldap_server.getDisplayValue() == 'LDAP Server US, UK, DF, MAU'){
if ((grUser.u_employee_type == "Canada") ||
(grUser.u_employee_type == "CANADA") ||
(grUser.u_employee_type == "UK")
){
empType = 'employee';
} else {
if ((grUser.u_employee_type == "") ||
(grUser.u_employee_type == "BUILT-IN")){
empType = 'service';
} else {
if ((grUser.u_employee_type == "NEMP") ||
(grUser.u_employee_type == "KNEMP")
){
empType = 'contractor';
}
}
} // End of US employee else
} // End of US
} // end of ldap server check
// If not set above, the value is 'undetermined'
result.setAttribute('employee_type', empType);
} // end of if (grUser.next())
return result;
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2016 01:01 PM
Hi Rajinis,
There should be a client script to load these values from the script include. Can you please check that too? Ensure that catalog client scripts shows as related list as i dont think it is visible out of the box. So you might have to show it and see if there are any client scripts that is causing this issue.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-29-2016 01:25 PM
Thanks Venkat, it was helpful.
There was a catalog client script, commented the bolded lines. Now it is not giving the error. did I do the right way? or anything more to dig into this?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
clearFields();
return;
}
var ga = new GlideAjax('u_ajaxGetUserInfo');
ga.addParam('sysparm_name','getUserRecord');
ga.addParam('search_field', 'sys_id');
ga.addParam('search_value', newValue);
ga.getXML(populateFields);
}
function populateFields(serverResponse) {
try{
var result = serverResponse.responseXML.getElementsByTagName("result");
g_form.setValue("vs_email", result[0].getAttribute("email"));
g_form.setValue("vs_location", result[0].getAttribute("location"));
g_form.setValue("vs_manager", result[0].getAttribute("manager"));
g_form.setValue("vs_department", result[0].getAttribute("department"));
g_form.setValue("vs_title", result[0].getAttribute("title"));
g_form.setValue("vs_cost_center", result[0].getAttribute("cost_centerDisplay"));
g_form.setValue("vs_work_phone", result[0].getAttribute("business_phone"));
g_form.setValue("vs_employee_id", result[0].getAttribute("employee_number"));
g_form.setValue("vs_ship_to", result[0].getAttribute("locationDisplay"));
g_form.setValue("vs_employee_type", result[0].getAttribute("employee_type"));
g_form.setValue("", result[0].getAttribute("objectguid"));
// Calculate the probably country they belong to
g_form.setValue("vs_HIDDEN_calc_country", result[0].getAttribute("calc_country"));
} catch(err){
//alert(err);
//clearFields();
}
}
function clearFields(){
g_form.clearValue("vs_location");
g_form.clearValue("vs_title");
g_form.clearValue("vs_manager");
g_form.clearValue("vs_email");
g_form.clearValue("vs_department");
g_form.clearValue("vs_cost_center");
g_form.clearValue("vs_employee_id");
g_form.clearValue("vs_work_phone");
g_form.clearValue("vs_ship_to");
g_form.clearValue("vs_HIDDEN_calc_country");
}