0% found this document useful (0 votes)
8 views2 pages

Userlist

The document outlines a JavaScript function that configures a field for selecting users in a system. It includes AJAX settings to fetch user data from an API, processes the results to create a list of user options, and defines how the selected user will be displayed. The functionality ensures that user selection is based on email, name, and login name, and sorts the results alphabetically.

Uploaded by

vithyavairamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Userlist

The document outlines a JavaScript function that configures a field for selecting users in a system. It includes AJAX settings to fetch user data from an API, processes the results to create a list of user options, and defines how the selected user will be displayed. The functionality ensures that user selection is based on email, name, and login name, and sorts the results alphabetically.

Uploaded by

vithyavairamani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 2

$CS.

referField("WorkOrder_Fields_UDF_CHAR63",
"users", {
multiple: false,
ajax: {
url: "/api/v3/users",
cache: false,
data: function (params) {
var input_data = sdpToJSON({
"list_info": {
"row_count": "100",
"search_fields": {
"email_id": params
},
"fields_required": ["id", "name", "email_id",
"login_name"]
}
});
return {
"input_data": input_data
};
},
results: function (res) {
let list = [];
let data = res["users"];
data.forEach((item) => {
let name = item.name || "";
let loginName = item.login_name || "";
let email = item.email_id || "";

if (name.trim() !== "" || email.trim() !== "" ||


loginName.trim() !== "") {
list.push({
id: email, // still using email as ID
text: name + " (" + loginName + ")" +
(email ? " - " + email : ""),
name: name,
login_name: loginName,
email: email
});
}
});

list.sort((a, b) => a.text.localeCompare(b.text));

return { results: list };


}
},
formatResult: function (object) {
// What is shown in the dropdown
return object.name + " (" + object.login_name +
") - " + object.email;
},
formatSelection: function (object) {
// What is shown after selection (also reflects in
request details view)
return object.name + " (" + object.login_name +
") - " + object.email;
}
});

You might also like