- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2023 02:15 PM - edited 08-04-2023 07:00 AM
Greetings all
My client script for onchange is getting invoked on existing record, however for a new record, neither onLoad or onChange doesnt seem to fire. Am I missing something obvious? My end goal is to display the assigned user Asset details on a field message. I am a n00b to servicenow world and to service operations workspace.
UPDATE : It only works when UI Type is set to ALL and is applied in Global scope and Isolate Script is checked OFF. The ServiceNow version is Tokyo. I wanted it only for SOW.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
alert ("In Func Affected System Name Prefetch Before IsLoading Check");
if (isLoading || newValue === '') {
return;
}
alert ("In Func Affected System Name Prefetch : old:" + oldValue + " ; new: " + newValue);
if(oldValue != newValue)
{
var userIdCaller = g_form.getValue('u_affected_end_user');
//console.log(userIdCaller);
var gaCaller = new GlideAjax('AjaxGetAssetValuesByUser');
gaCaller.addParam('sysparm_name', 'getFieldValues_JSON');
gaCaller.addParam('sysparm_fields', 'ci,model_category');
gaCaller.addParam('sysparm_sys_id', userIdCaller);
gaCaller.getXML(CallbackAsset);
}
}
function CallbackAsset(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
var parsedData = JSON.parse(answer);
var dataLen = parsedData.length;
var result = [];
for (var i = 0; i < dataLen; i++) {
result.push(parsedData[i].model_category + ": " + parsedData[i].ci);
}
var text = 'System: ' + result.join(', ');
//clear the previous message
g_form.hideFieldMsg('u_affected_system_name', true);
//show the system names as comma seperated text in a warning block
g_form.showFieldMsg('u_affected_system_name', text, 'warning');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:59 AM
My suggestion to you is make copy client script separately for SOW workspace ,
Above is OOB client script on "Resolution details visibility on state"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:59 AM
My suggestion to you is make copy client script separately for SOW workspace ,
Above is OOB client script on "Resolution details visibility on state"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 10:20 AM
Thanks Abhijit. The sow_new_record worked for new record. Can we set multiple views instead of duplicating the client script, one of existing vs. one for new??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2023 07:35 AM
Not sure, but I guess if you keep it blank it should work for all views, please refer to documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 09:21 PM - edited 03-06-2024 09:21 PM
The code below does not work in sow_new_record view Interaction Management for Service Operations Workspace Application Scope, it does not work in Global on the new Record either. It is highlighting the field but not setting the values on New Record page. UI Type is set to All.
function onChange(control, oldValue, newValue, isLoading) {
if (!g_form.hasField('opened_for'))
return;
if (!newValue)
return;
g_form.getReference('opened_for', ref);
function ref(user) {
if (user.vip == 'true') {
g_form.setValue('vip', user.vip.toString());
g_form.showFieldMsg('opened_for', 'This is a VIP user', 'error');
}
if (g_form.hasField('user_name')) {
g_form.setValue('user_name', user.user_name.toString());
}
}
}
