- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 07:02 AM
Hi ,
In Incident form Show Impacted (reference field ) and Show Start Date are two columns and These two columns are part of one Table only.
When I select the Show Name in show impacted column then it need to display related Show Date in Show Start Date field.
Instead it is showing value as undefined when selecting particular show name even after it has the date.
Please provide suggestions.
Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 07:51 AM - edited 04-02-2025 07:56 AM
Try below script.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var userObject= g_form.getReference("u_show_impacted", doAlert);
function doAlert(userObject) {
g_form.setValue('u_show_start_date', userObject.getValue('u_start_date')); //Make sure to use the correct field name
}
}
NOTE: While setting the date value you are not picking the correct field name. Check that. Also please share the snap of your onchange client script configuration.
As per my script, you onchange client script should be configured on "Show impacted" field and UI type should be "All"
Regards ,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 08:41 AM
you should have script when value changes so do this and not when form loads
Ensure all field names are correct
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('u_show_start_date');
if (oldValue != newValue)
var userObject = g_form.getReference("u_show_impacted", doAlert);
function doAlert(userObject) {
g_form.setValue('u_show_start_date', userObject.getValue('u_start_date'));
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2025 03:54 AM
Hi @Ankur Bawiskar ,
Thank you so much for your quick assistance and I achieved it with your initial code itself by adding date format conditions (bold and Underlined).
Here is the Script for reference
Client Script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 08:57 AM
Thank you @Ankur Bawiskar script was working but date format taking (in incident form) in opposite
Table data:
Incident reflection:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:34 AM
the value you are getting convert that to logged in user's format.
To get the correct date format, you can use GlideAjax call and get the value in logged in user's and return that value
Why not show that Date field as dot walked from reference field and no scripting required?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:38 AM
Could you please help me with an example please @Ankur Bawiskar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:45 AM
something like this
Script Include: it should be client callable
var DateTimeUtils = Class.create();
DateTimeUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDateValue: function() {
var sysId = this.getParameter('sysparm_sysid');
var rec = new GlideRecord('tableName');
if (rec.get(sysId)) {
return rec.u_start_date.getDisplayValue();
}
},
type: 'DateTimeUtils'
});
onChange client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ajax = new GlideAjax('DateTimeUtils');
ajax.addParam('sysparm_name', 'getDateValue');
ajax.addParam('sysparm_inc', newValue);
ajax.getXML(getDate);
function getDate(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('u_show_start_date', answer);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2025 09:56 AM