Having issues with a script

Lindsey6
Giga Contributor

Hello,

I am currently working on the training module (Integrating with ServiceNow; Exercise: Create an inbound web service) and the script that is provided is invalid. I am looking for some help/guidance on how to fix it so I can move forward with this training.

Error: "Could not save record because of a compile error: JavaScript parse error at line (27) column (2) = syntax error (<refname>;line 27)

//Convert source field to string
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
      var name = source.u_name.toString();

//Split names anywhere there is a space
      var split_names = name.split (" ");

//Find the number of names
      var num_names = split_names.length;

//If there is only one name map it to the last name
          if (num_names == 1) {
              target.last_name = split_names[0];
}

//if there are two names map to first and last name      
          if (num_names == 2) {      
              target.first_name = split_names[0];
          target.last_name = split_names[1];
}

//if there are more than 3 names combine into one middle name
      if (num_names >= 3) {
          target.first_name = split_names.shift();
      target.last_name = split_names.pop();
          var middle_name = split_names.join(" ");
})(source, map, log, target);

Thank you,

Lindsey

8 REPLIES 8

Rajesh Mushke
Mega Sage
Mega Sage

Yes, it's Syntax error




Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

Sadasiva Reddy
Giga Guru

Hi Herman,



You have used split_names[0], but you have defined an array. once check with that.



regards,


Sadasiva



Please mark helpful/ correct based on the impact


Lindsey6
Giga Contributor

Shiva, that worked, thanks so much for your help!


You're welcome.



Good syntax indentation makes this error easier to detect. Dedicated code editor enforces clean indentation.