- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 06:50 AM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 02:46 PM
@abbassi There are two issues with your client scripts.
1. g_form.getReference ('user'); getReference call without a callback function are not supported in Service Portal. For more information please refer to https://www.servicenow.com/community/developer-forum/g-form-getreference-is-not-working-in-service-p...
2. var userRecord = new GlideRecord("sys_user"); Synchronous GlideRecord queries in client script in Service portal are not supported. Please consider shifting your GlideRecord queries to a Script Include and call them via GlideAjax.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 07:16 AM
Hi,
Is the 'UI Type' field on the client script set to "All"?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 07:19 AM
Yes , I cheked All
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2024 12:14 PM - edited 05-24-2024 12:59 PM
Try adding debug and test:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var userinfo = g_form.getReference ('user');
//g_form.setValue ('ldap', userinfo.user_name);
// Fonction pour réinitialiser les champs
function resetFields() {
alert("client script: resetFields() called");
g_form.setValue('email', '');
g_form.setValue('bu_or_external_supplier', '');
g_form.setReadOnly('email', false);
g_form.setReadOnly('bu_or_external_supplier', false);
// g_form.setReadOnly('ldap', false);
}
// Fonction pour définir les champs
function setFields(email, company) {
alert("setFields called, email = " + email + "company = " + company);
g_form.setValue('email', email);
g_form.setValue('bu_or_external_supplier', company);
// g_form.setValue('ldap', ldap);
g_form.setReadOnly('email', true);
g_form.setReadOnly('bu_or_external_supplier', true);
//g_form.setReadOnly('ldap', true);
}
var userRecord = new GlideRecord("sys_user");
if (!userRecord.get(newValue)) {
alert("userRecord get failed");
resetFields();
return;
}
var emailUser = userRecord.getValue('email');
var companyID = userRecord.getValue('company');
//var ldapUser = userRecord.getValue('ldap');
alert("setting emailUser = " + emailUser + ", companyID = " + companyID);
if (!companyID) {
alert("calling resetField() due to companyID");
resetFields();
return;
}
var companyRecord = new GlideRecord('core_company');
if (!companyRecord.get(companyID)) {
alert("calling resetField() due to companyID not being found");
resetFields();
return;
}
var companyName = companyRecord.getValue('name');
if (companyName === 'GROUPE') {
alert("calling setFields() due to companyName being GROUPE");
setFields(emailUser, companyName);
} else {
alert("calling resetFields() due to companyName not being GROUPE");
resetFields();
}
}
And refer here:
service-portal client-script-reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2024 11:56 AM
Hello @Bert_c1
It 'doesn't work