Append the output of two client scripts.

Shidhi
Tera Contributor

Hi,

 

I have two checkboxes Server and SPM Test Names if these checkboxes are true then I need to populate those names in a new field.

I have written individual Onchange client scripts so either the Server or SPM Test Name is getting placed into the variable but I want to have both names(Server,SPM Test Names) to be placed if both checkboxes are selected.

Please find below my code:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == 'true') {
        g_form.setValue('request_type', 'Server Names');
    }
   else
   g_form.setValue('request_type', ' ');
}

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   if(newValue == 'true'){
	g_form.setValue('request_type', 'SPM Test Name');
   }
   else
   g_form.setValue('request_type', ' ');
}


Please help. Thank you!

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If the Catalog Item variable names are 'server' and 'spm_test_names', something like this should work for server onChange:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    if (newValue == 'true') {
        if (g_form.getValue('spm_test_names') == 'true') {
            g_form.setValue('request_type', 'Server Names SPM Test Name'); 
        } else {       
            g_form.setValue('request_type', 'Server Names');
        }
    } else if (g_form.getValue('spm_test_names') == 'true') {
        g_form.setValue('request_type', 'SPM Test Name');
    } else {
       g_form.setValue('request_type', ' ');
    }
}

If 'Server Names' and 'SPM Test Name' are not literal values you can use a + to concatenate within the setValue...

View solution in original post

9 REPLIES 9

anshul_goyal
Kilo Sage

Hi @Shidhi 

You can create a Business rule for this requirement instead of a Client Script and follow the below steps:

1. Create a Business Rule 

2. Add conditions in the business rule like (Server is True and SPM Test Names is True).

3. In the 'Actions' tab use the Set field values option to set particular values on the field.

4. Otherwise, you can use the 'Advance' tab to set the particular value on the field.

Please mark my solution as Helpful and Accepted, if it works for you in any way!

Thanks

Hi @anshul_goyal 

This was a catalog item, and those checkboxes are catalog item variables. Could you please suggest an approach here.

 

Thank you!

@Shidhi, Is the request type field on the catalog item or somewhere else?

@Shidhi Can you please confirm?