The CreatorCon Call for Content is officially open! Get started here.

If Two or three filed are not empty then the third field should be shown the defined value

Madhuavandhy
Tera Contributor

Madhuavandhy_2-1686739643747.png

 

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?

 

 

 

 

2 ACCEPTED SOLUTIONS

Sandeep Rajput
Tera Patron
Tera Patron

@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.

View solution in original post

jaheerhattiwale
Mega Sage

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

2 REPLIES 2

Sandeep Rajput
Tera Patron
Tera Patron

@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.

jaheerhattiwale
Mega Sage

@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.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023