- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 06:16 AM
Hi all,
I need your help once again.
I have this client script on HR case that check if an URL is added in the additional comment. If yes, then create the hyperlink.
However when the link is "www.google.be" then cae is submitted but link is string and when the url contains "http(s)" then client script give an error.
Any idea to help on this ?
function onSubmit() {
// check comments and add href
var new_comments = g_form.getValue('comments')+'';
if(new_comments!=''){
g_form.setValue('comments', urlify(new_comments));
}
// check notes and add href
var new_notes = g_form.getValue('work_notes')+'';
if(new_notes!=''){
g_form.setValue('work_notes', urlify(new_notes));
}
}
// function to create link
function urlify(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.replace(urlRegex, function(url) {
alert($_URI);
return '[code]<p><a class="web" target="_blank" href="' + url + '">' + url + '</a></p>[/code]';
});
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 07:54 AM
well, there is only one place where you use the URI... the alert. I assume the alert is there only for debug purposes. What happens if you remove/comment that line?
The $-notation seems to be some jQuery syntax which would trigger a best practice violation as well. You should work with g_form.getValue / g_form.getDisplayValue instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 06:25 AM
What kind of error do you receive? Have you checked the javascript console of your browser?
In any case, why render that on client side and not as a business rule on server side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 07:32 AM
I tried to add the link http://google.be
onSubmit script error: ReferenceError: $_URI is not defined:
function onSubmit() {
var new_comments = g_form.getValue('comments')+'';
if(new_comments!=''){
g_form.setValue('comments', urlify(new_comments));
}
var new_notes = g_form.getValue('work_notes')+'';
if(new_notes!=''){
g_form.setValue('work_notes', urlify(new_notes));
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 07:54 AM
well, there is only one place where you use the URI... the alert. I assume the alert is there only for debug purposes. What happens if you remove/comment that line?
The $-notation seems to be some jQuery syntax which would trigger a best practice violation as well. You should work with g_form.getValue / g_form.getDisplayValue instead.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-19-2016 08:09 AM
Yeah, either comment out the alert line or define/assign $_URI before you use it.