The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Getting the value of a "radio" button in record producer

F_bio Santos
Kilo Sage

Hi everyone, Im trying to set a value of a field "Confidentiality" depending on 3 radio buttons on a record producer, the buttons are: 

"Public" -> Choices: "yes"
"Confidential" -> Choices: "yes"
"Restricted" -> Choices: "yes"

When I click one of the buttons it clears the value of the others, what Im trying to do is if the person chooses for exemple "Public", the field "Confidentiality" will be "Public" I've tried with this code:

function onSubmit() {
   //Type appropriate comment here, and begin script below
   if(public_option_1 == 'yes'){
         u_confidentiality = 'Public';
   }
   else if(confidential_option1 == 'yes'){
	   	u_confidentiality = 'Confidential';
   }
   else{
	   u_confidentiality = 'Restricted';
   }
}


But it didnt work does any one know how to do this ?

1 ACCEPTED SOLUTION

Tushar
Kilo Sage
Kilo Sage

Hi @F_bio Santos 

 

Try below -

 

function onSubmit() {
  var publicOption = g_form.getValue('public_option');
  var confidentialOption = g_form.getValue('confidential_option');
  var restrictedOption = g_form.getValue('restricted_option');

  var confidentialityField = 'u_confidentiality'; // Replace with the actual field name

  if (publicOption == 'yes') {
    g_form.setValue(confidentialityField, 'Public');
  } else if (confidentialOption == 'yes') {
    g_form.setValue(confidentialityField, 'Confidential');
  } else if (restrictedOption == 'yes') {
    g_form.setValue(confidentialityField, 'Restricted');
  }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@F_bio Santos 

Can you share the complete code along with screenshots?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Tushar
Kilo Sage
Kilo Sage

Hi @F_bio Santos 

 

Try below -

 

function onSubmit() {
  var publicOption = g_form.getValue('public_option');
  var confidentialOption = g_form.getValue('confidential_option');
  var restrictedOption = g_form.getValue('restricted_option');

  var confidentialityField = 'u_confidentiality'; // Replace with the actual field name

  if (publicOption == 'yes') {
    g_form.setValue(confidentialityField, 'Public');
  } else if (confidentialOption == 'yes') {
    g_form.setValue(confidentialityField, 'Confidential');
  } else if (restrictedOption == 'yes') {
    g_form.setValue(confidentialityField, 'Restricted');
  }
}

 

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Regards,
Tushar