- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-07-2023 11:19 PM
Hi there
on a catalog item i have two fields
one is a reference field sys_user - user_list
another is a free text field - service_account_users
both are non mandatory
i need a onsubmit script which stores the value on another single text field 'combined_list' as comma separated values
possible scenarios
user_list & service_account_users
1) both fields are populated
2) any one of the fields are populated
3) both fields are not populated
please provide me with a example
Thank You
Levino
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 04:29 AM
I updated it with all 4 scenarios; enhance it as per your requirement
function onSubmit() {
var user = g_form.getValue('user_list');
var service = g_form.getValue('service_account_users');
if(user!='' && service!='')
{
g_form.setValue('combined_list', user + service);
}
else if(user != '' & service == ''){
// add your logic
g_form.setValue('combined_list', user);
}
else if(user == '' && service != ''){
// add your logic
g_form.setValue('combined_list', service);
}
else if(user == '' && service == ''){ // both are empty so you decide what needs to be done
// add your logic
}
}
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
06-08-2023 04:29 AM
I updated it with all 4 scenarios; enhance it as per your requirement
function onSubmit() {
var user = g_form.getValue('user_list');
var service = g_form.getValue('service_account_users');
if(user!='' && service!='')
{
g_form.setValue('combined_list', user + service);
}
else if(user != '' & service == ''){
// add your logic
g_form.setValue('combined_list', user);
}
else if(user == '' && service != ''){
// add your logic
g_form.setValue('combined_list', service);
}
else if(user == '' && service == ''){ // both are empty so you decide what needs to be done
// add your logic
}
}
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
06-07-2023 11:46 PM
Use the following code in your Onsubmit script section :
{
var user;
var service;
if(g_form.getValue('user_list')!='')
{
user=g_form.getValue('user_list')
}
if(g_form.getValue('service_account_users')!='')
{
service=g_form.getValue('service_account_users')
}
var combined=user + ", " + service;
g_form.setValue('combined_list',combined);
}