- 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-03-2023 04:32 PM
Hi there,
Could you please verify the UI Type of the client script? I would try setting it to All if it isn't already.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:01 AM
Thanks for your response, Alex. It seems to only work 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 this functionality only for SOW forms, but cannot seem to apply only on those views.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:35 AM
I do not understand your exact query, but when form is loading then below section is getting called , onchange only invoke on fieldvalue is changed
if (isLoading || newValue === '') {
return;
}
isloading() function is getting called when form is loading, I would suggest call your GlideAjax in above if loop as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2023 07:41 AM
That is my issue - the form for Create New Incident in SOW, the onchange is not invoked, even on field value change, until it is in Global Scope and Isolate Script is checked off. For a normal edit of existing record, it seems to work with me specifying a view and Isolate Script is checked on. I do not want to apply this onchange globally, but only in SOW. Searching for means on how to do it selectively in SOW. Thanks.
