- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 03:47 AM
I am new to Servicenow , I need to develop my knowledge
For example the name ,country and company are not empty then the report filed should be 'Full cooked' . How to write the java script?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 05:19 AM
@Madhuavandhy There are multiple ways to achieve this, either you can choose to create onChange Client scripts on Name, Country and Company fields and check if rest of the fields are populated and if all the fields are entered by the user then set the report field to 'Fully cooked'.
In case if you wish to populate the value during form submission then you can create an onSubmit client script as follows.
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('u_name') && g_form.getValue('u_country') && g_form.getValue('u_company')) {// replace the field values as per your field names
g_form.setValue('u_report', 'Fully Cooked');
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 05:38 AM
@Madhuavandhy You can write 3 onchange client script on name, country and company each and add below code to all 3 client scripts
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('<NAME FIELD NAME HERE>') && g_form.getValue('<COUNTRY FIELD NAME HERE>') && g_form.getValue('<COMPANY FIELD NAME HERE>')) { // replace the field values as per your field names
g_form.setValue('u_report', 'Fully Cooked');
}
}
Note: This code will work when the name, country or company changes. If you want the result on submit then use the code suggested by @Sandeep Rajput
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 05:19 AM
@Madhuavandhy There are multiple ways to achieve this, either you can choose to create onChange Client scripts on Name, Country and Company fields and check if rest of the fields are populated and if all the fields are entered by the user then set the report field to 'Fully cooked'.
In case if you wish to populate the value during form submission then you can create an onSubmit client script as follows.
function onSubmit() {
//Type appropriate comment here, and begin script below
if (g_form.getValue('u_name') && g_form.getValue('u_country') && g_form.getValue('u_company')) {// replace the field values as per your field names
g_form.setValue('u_report', 'Fully Cooked');
}
}
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 05:38 AM
@Madhuavandhy You can write 3 onchange client script on name, country and company each and add below code to all 3 client scripts
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (g_form.getValue('<NAME FIELD NAME HERE>') && g_form.getValue('<COUNTRY FIELD NAME HERE>') && g_form.getValue('<COMPANY FIELD NAME HERE>')) { // replace the field values as per your field names
g_form.setValue('u_report', 'Fully Cooked');
}
}
Note: This code will work when the name, country or company changes. If you want the result on submit then use the code suggested by @Sandeep Rajput
Please mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023