- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 12:03 AM
I have a variables called Department and Sub Department.The requirement is append .sub to the value entered on Department. It should be on form load.
Eg Department is Computer then Sub Department should be Computer.sub
I have written script as below but it is not working.It shows undefined.
function onLoad() {
var control = g_form.getControl('department');
var tm = control+'.sub';
control.onkeyup = myCustomFunction;
function myCustomFunction() {
g_form.setValue('subDepartment', tm.value);
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 04:16 AM
Hi,
can you alert the value of department; is the field name correct?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('sub_department');
var abc = g_form.getValue('department');
alert('department is: ' + abc);
g_form.setValue('sub_department', abc + '.sub');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 12:20 AM
Hi,
what type of field is department and Sub Department?
Is Department auto-populated on form load or you would require onchange client script in department field?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 12:23 AM
both are single line text variables.
I need it like when user type department at that time sub department get replicated with .sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 12:25 AM
Hi,
I would recommend using onChange script for this; I don't think it would happen simultaneously
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('sub_department');
var abc = g_form.getValue('department');
g_form.setValue('sub_department', abc + '.sub');
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 04:03 AM
It gives me output as undefined.sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2020 04:16 AM
Hi,
can you alert the value of department; is the field name correct?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('sub_department');
var abc = g_form.getValue('department');
alert('department is: ' + abc);
g_form.setValue('sub_department', abc + '.sub');
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader