Getting missing semicon before statement error in background script though it is present

GD11
Tera Expert

Below is the code that I am trying to run in background script to get URL of the knowledge articles, once we get the URL I want to append it with 'href=" ' tag along with it's header, but it is giving me error when I put that lien in the code, other runs fine if I remove line 20.  not sure what is missing.

Code :

var gr = new GlideRecord("u_kb_template_teutr_production_installation_guide");
gr.addQuery("number", "KB0051586");
gr.query();
if (gr.next()) {
 var str = gr.u_introduction;
var newstr ='';
gs.print("Intro value" + str);
var regex = /(\[(?:\[??[^\[]*?\]\]))/g;
var arr = str.match(regex);
for(var i = 0; i < arr.length; i ++) {
    var title = arr[i].split("|")[0].replace("[[", "").trim();
       var solutionId = arr[i].split("|")[1].replace("]]", "").trim();
    gs.print("\n\nTitle: " + title + "\nSolution ID: " + solutionId);
    var gr1 = new GlideRecord("kb_knowledge");
gr1.addQuery("u_ra_id", solutionId);
gr1.query().id
if (gr1.next()) {
   gs.print("article number" + gr1.number);
var url = gs.getProperty('glide.servlet.uri') + gr1.getLink();
gs.print("URL" + url);
//var newurl = 'href=\"' + url + '\" ' + 'target=\"_blank\"';  
var newurl ='href="'+url+'" target="_blank"';  

gs.print("newurl" + newurl );
var html = newurl+ '<' + title.toString() + '</a>';


gs.print("complete HTML" + html);
}
newstr=str.replace(arr[i], html);
gs.print("new string " + newstr);
gr.update();

}

Error : Javascript compiler exception: missing ; before statement (null.null.script; line 20) in:

I want to form HTML text like below:

 

find_real_file.png

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage
Mega Sage

Hi,

 

Try this

var newurl = 'href=\"' + url + '\" ' + 'target=\"_blank\"';

View solution in original post

3 REPLIES 3

Muhammad Khan
Mega Sage
Mega Sage

Hi,

 

Try this

var newurl = 'href=\"' + url + '\" ' + 'target=\"_blank\"';

Vamsi Sreenivas
Giga Guru

Update as below:

var newurl ='href="'+url+'" target="_blank"';  ==== this is line 20

 

Regards,

Vamsi S

GD11
Tera Expert

URL is working fine now , thanks for your quick help but unable to replace it in HTML body below.

Highlighted text should be replaced with  result in HTML field returned in above code.

 

find_real_file.png

 

find_real_file.png