- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 12:06 AM
Hi All
I need to validate the languages in user table while end user is sending data through payload. The similar kind of validation I did for company and its working fine but how we can give the same for a drop down choice?
sample company filed validation->
var user_company = body['Company'].toString().trim();
if (user_company == '' || user_company == null || user_company == undefined)
return {
"Status": "Enter the Company"
};
var company = new GlideRecord('core_company');
company.addQuery('name', user_company);
company.query();
if (company.next()) {
user.company = company.getUniqueValue();
} else {
return {
"Status": "Invalid company"
};
}
Solved! Go to Solution.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 02:13 AM
Hi,
if it's a creation then against what you wish to perform the validation?
are you saying you wish to check the sys_choice table and check value they pass is present in choice list or not?
in that case you can query sys_choice with element - preferred_language
name=sys_user^element=preferred_language
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-30-2022 02:34 AM
like this?
var lang = new GlideRecord('sys_choice');
lang.addQuery('name', 'sys_user');
lang.addQuery('element', 'preferred_language');
lang.query();
if (lang.next()) {
user.lang = lang.getUniqueValue();
} else {
return {
"Status": "Invalid language"
};
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 02:47 AM
yes
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-30-2022 03:30 AM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-30-2022 05:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2022 02:31 AM
Hi,
The first question would be - are you getting the user_name in the payload, if yes, then you can run GlideRecord on "sys_user" table and validate it.
user.preferred_language =<language>;
Please elaborate the issue
Regards,
Snehangshu Sarkar