Having issues with a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 05:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 05:04 AM
Hi Herman,
Remove space between split and ()
replace below code at your second line
var split_names = name.split(" ");
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-28-2024 09:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 05:18 AM
Hi Rajesh,
What line do you want me to remove the space between splint and () ?
I also tried replacing line # 2 with the code you provided and it brought up a lot more errors.
Thanks,
Lindsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-11-2017 05:38 AM
Hi Lindsey,
Rajesh answer is not correct. You were missing a bloc closure at the end: }
Here is the corrected version:
//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);
Tip: I suggest you download a dedicated code editor to get line and column numbers. I use Atom, a free editor that runs on Windows and MacOs.