client script is not working on service portal while it is working on console
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-20-2023 08:07 PM - edited 04-20-2023 09:21 PM
Kindly help me with the below code it is not working on service portal while it is working on ITIL console page
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var buss_ser=g_form.getValue('u_business_services');
var bus_app_name=g_form.getReference('u_business_services').name;
if(buss_ser!=''){
var user_bd='';
var id = g_form.getValue('cmdb_ci');//replace 'u_first_field' with the name of your reference field.
var user = new GlideRecord('cmdb_ci_appl');
user.addQuery('sys_id',id);
user.query();
if ( user.next() ) {
if(user.u_functional_support_group != '')
{
g_form.setValue('assignment_group', user.u_functional_support_group);
}
else
{
if(bus_app_name=='Not Applicable'){
//alert('Not Applicable');
return;
}
user_bd = g_form.getReference('u_requested_for').u_bd___scope;
//alert("user_bd"+user_bd);
if (user_bd == "FCE BD SOUTHWEST MED" || user_bd == "FCE BD SOUTHWEST SP")
{
g_form.setValue('assignment_group',"3c09b8230f5bb54041dd715ce1050ef5");
}
else
{
g_form.setValue('assignment_group',"f2393c230f5bb54041dd715ce1050e62");
}
}
}
}
else{
alert('Please select a Business Service.');
var app_name=g_form.getReference('cmdb_ci').name;
if(app_name!='Not Applicable'){
g_form.setValue('assignment_group',"");
//alert('Not Applicable');
return;
}
g_form.setValue('cmdb_ci',"");
}
//Type appropriate comment here, and begin script below
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 05:11 AM
@Prashant Kumar There are a couple of things you need to update
It's not best practice use glide record in client script instead of it you can use glide ajax to get the data from server
side.
You can refer this link
Please mark the answer correct/helpful based on Impact.
Regards,
RJ

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2023 10:41 AM
@Prashant Kumar Service Portal doesn't support synchronous API calls hence your script is working on the backend and not on the Service Portal.
First of all, you need to make call g_from.getReference() calls asynchronous by providing a call back method. e.g.
var caller = g_form.getReference('caller_id', popCallerInfo);
//Nested 'getReference' callback function for variable access
function popCallerInfo(caller){
//Location setting section
if(loc && !isLoading && newValue != oldValue){
g_form.setValue('location', caller.location);
}
}
Secondly, you are making a glide record query directly inside the client script
var user = new GlideRecord('cmdb_ci_appl');
user.addQuery('sys_id',id);
user.query();
Such GlideRecord queries can work on the backend view but since they are synchronous calls they are not supported on Service Portal. Ideally this should have been called using a script include.
Here is a good tutorial on the Script Include https://www.learnnowlab.com/Script-Include/#:~:text=Script%20include%20is%20used%20to,and%20in%20oth....
Make these changes and your client script will work on the Service Portal too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 08:55 AM
can you just suggest the script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2023 12:35 AM
Do check UI type of your client script is set to 'All'.
Regards,Sushant Malsure