Need to populate table name based on Type field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:10 AM
HI
I have a requirement,
In a flashes form (name of the table flashes), there is choice field called type. choices: user, location and account.
and there another field called table name its data type is table name so this field will display all tables present in the instances.
Now, if i select user from type the user table (sys_user) table need to be default in table name field
IF I select location from type field then location table (cmn_location) need to be default in table name field...similarly for account means account table.
Is it possible to do so?
If it is achievable, If so, please do let me know how we can achieve this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 02:58 AM
Hi @suuriya,
Yes, it is possible to do. Please use the below code for your reference:
Client Script:
Type: onChange
Field: Type
Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.clearValue("u_table_name");
return;
}
//Type appropriate comment here, and begin script below
if (newValue == "User") {
g_form.setValue("u_table_name", "sys_user");
} else if (newValue == "Location") {
g_form.setValue("u_table_name", "cmn_location");
} else if (newValue == "Account") {
g_form.setValue("u_table_name", "customer_account");
}
}
I hope this will help you solve your problem. Please mark it as Accepted and Helpful.
Thanks and Regards,
Anshul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 03:00 AM
did you try adding ref qualifiers?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 03:07 AM
Hello @suuriya ,
This is possible. You can configure "onChange" client script on your current table.
I have written a demo script for you.
u_reference will be your "Table type" and you can set "sys_id" of respective tables there.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2023 03:27 AM
Hi @suuriya
We can write onChange client script on "Type" field.
//Use your fields backend name
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading) {
return;
}
var getType = g_form.getValue('u_type');
if (getType == 'user') {
g_form.setValue('u_table', 'sys_user'); //put backend name of tables
} else if (getType == 'location') {
g_form.setValue('u_table', 'cmn_location'); //put backend name of tables
} else if (getType == ''){
g_form.clearValue('u_table');
}
}
If possible make "Table name" field as readonly.
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates