How to extract url using Business Rule?

Annie10
Tera Contributor

Hello,

I have the following URL in the the RITM description field.  How can copy this link to the work note as a clickable link?

This TEST LINK<https://gcc02.safelinks.protection.outlook.com/?url=https%3Add%2F%2Fmwdsocal.sharepoint.com%2Fsites%...> is Approved.

 

I have tried before insert Business Rule script. However, I screwed up somewhere in the code that make it did not work.  Can someone please help.  Thank you


var description = '' + current.description;
var myLink = description.match(/(?:http[s]*\:\/\/)*(.*?)\.(?=[^\/]*\..{2,5})/i);
current.work_notes = '[code]<a href=' + myLink + ' target="_blank">My Link</a>[/code]';

4 REPLIES 4

Mohith Devatte
Tera Sage
Tera Sage

Hello @Annie10 

try this line

current.work_notes = [code]'<a href='+current.description.toString() + ' target="_blank">My Link</a>'[/code];

 

Hope this helps 

Mark my answer correct if this helps you 

Thanks

 
 

Hi Mohith,

Thank you for your suggestion.  Your code copied the entire text in the description field over to the work note.  I would it to search for the URL in the description field an copy only the URL over the work note. 

ScottW1
Tera Contributor

Hi There Annie10, Did you ever find a solution to this? Im trying to do the exact same thing. I think Mohith was close but needed an inner statement on the current.description.toString() to perform the match 

 

Hello @ScottW1 @Annie10 ,

I tried below code ->

 

	var text = 'follow this reply https://google.com/ It should help you';
	var urlRegex = /(\b(((https?|ftp|file):\/\/)|(ww+))[\-A-Z0-9+&@#\/%?=~_|!:,.;]*[\-A-Z0-9+&@#\/%=~_|])/ig;
	var match = text.match(urlRegex);
	if (match) {
		gs.print(match[0]);
	}
	
	
	Result printed - https://google.com/

 

Hope it helps.

If it helps you, kindly mark this as Accepted Solution/Helpful and help in closing this thread.

Best Regards,

Shubham