Skip to main content
DanielleS76
Participant
April 13, 2026
Answered

Populating one field based on the entry in another field

  • April 13, 2026
  • 2 replies
  • 37 views

Hi,

I know this has been asked before and I’ve used those responses to get to this point but I’m still getting a syntax error.  I have a list of physicians in a pull-down list.  When a user selects one of them, I need their NPI and license number to populate the next two corresponding fields (“NPI” and “License,” respectively).  I am attaching this on the “Validate” tab for the “Physician” field referenced above and I have the options set to “Commit selected value immediately.” The error when I try to save the script is “SyntaxError: syntax error 12: at line 13.”  This is the script I’m using (values changed to generic ones):

var NPI = this.getField("NPI");
var License= this.getField("License");

if(event.value == "Dr. A"){
NPI.value = "123456";
License.value = "Alicense";}
else if(event.value == "Dr. B"){
NPI.value = "654321";
License.value = "Blicense";}
else if(event.value=== "Dr. C")
NPI.value = "7891011";
License.value = "Clicense";}

else{
NPI.value = "";
License.value = "";}

 

Thanks for the assistance in advance!  

    Correct answer Bernd Alheit

    I miss one { in your script.

    2 replies

    Nesa Nurani
    Community Expert
    Community Expert
    April 14, 2026

    As Bernd mentioned there is missing bracket in ‘else if’ statement for Dr. C , here is another way you can achieve same (cleaner and easier to edit especially if you have large list):

    var map = {
    "Dr. A": { NPI: "123456", License: "Alicense" },
    "Dr. B": { NPI: "654321", License: "Blicense" },
    "Dr. C": { NPI: "7891011", License: "Clicense" }
    };

    var data = map[event.value] || { NPI: "", License: "" };

    this.getField("NPI").value = data.NPI;
    this.getField("License").value = data.License;

     

    DanielleS76
    Participant
    April 16, 2026

    Thank you for the alternative version!  I had already built it out in the way I had shown but your version is much easier. I will use that for my future builds of other related fields. Many thanks again!  

    Bernd Alheit
    Community Expert
    Bernd AlheitCommunity ExpertCorrect answer
    Community Expert
    April 14, 2026

    I miss one { in your script.

    DanielleS76
    Participant
    April 16, 2026

    Thank you so much!  It was as simple as one missing bracket and now it’s working perfectly.  Thank you!!