Answered by:
Add CRM HTPP clickable link in notes tab

Question
-
Hello,
I would like that the Users of MS dynamics CRM 4 be able to add HTTP clickable link in the Notes tab from the opportunity entity by example. Is it possible to customize the CRM to do that? (Because when I try to do that, it is add just text and not a clickable link).
Thanks a lot for your help .
- Moved by Don ChangModerator Friday, July 16, 2010 2:32 PM Development Question (From:CRM)
Thursday, July 15, 2010 9:25 AM
Answers
-
A possible quick and dirty solution is to change the functionality above to one that builds an html section for each annotation.
It’s fair to say that this solution is much more risky and if there was ever a line between good unsupported and bad unsupported this is definitely bad. Here is a working example…
function OnCrmPageLoad()
{
window.NotesToolbar = new InlineToolbar("new_openurl");
NotesToolbar.AddButton("btnShowLinks","Show Links","15%",OpenSelectedUrl);
}
function OpenSelectedUrl()
{
var NotesIframe = document.all.notescontrol.contentWindow;
var Annotations = NotesIframe.document.getElementsByTagName("TextArea");
for(var i = 0; i < Annotations.length ; i++)
{
var Note = Annotations[i];
var NoteLink = Note.Link;
if (NoteLink == null)
{
NoteLink = NotesIframe.document.createElement("SPAN");
NoteLink.style.cssText = "border-top:1px solid gray;line-height:22px;width:100%;background-color:pink";
Note.Link = NoteLink;
Note.parentElement.appendChild(NoteLink);
}
NoteLink.innerHTML = UrlToLink(Note.innerText);
}
}
function UrlToLink (text)
{
if( !text ) return text;
text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url)
{
nice = url;
if( url.match('^https?:\/\/') )
{
nice = nice.replace(/^https?:\/\//i,'')
}
else
{
url = 'http://'+url;
}
return '<a style="text-decoration:underline;color:blue;" target="_blank" rel="nofollow" href="'+ url +'">'+ nice +'</a>';
});
return text;
}
OnCrmPageLoad();
GI CRM Blog * GI Website- Marked as answer by DavidJennawayMVP, Moderator Thursday, August 5, 2010 3:40 PM
Wednesday, July 21, 2010 12:24 PM
All replies
-
Any Ideas or tips to do that?Tuesday, July 20, 2010 9:45 AM
-
-
I confirm
Even if I add html content directly in DB, the rendered text is not interpreted as HTML
My blog : http://mscrmtools.blogspot.com
All my tools on my new dedicated site: MSCRMTools RepositoryTuesday, July 20, 2010 12:21 PMModerator -
if this was a necessity then i would build a simple aspx page that would read and display all the notes, when HTML was found in the text, it would render as html. i would then use javascript to hide the tab and put the custom aspx page in a iframe on another tab and rename it notes.
Jonathan Nachman MBSP, MCTS
Technical CRM Consultant for KMS SoftwareTuesday, July 20, 2010 1:09 PM -
Thanks for all you answer.
Jonathan, I'm interesting to know more about your workaround. If I do what you say, Will the users be able to add a note from this page like the original "notes" page?
I'm not really a developper but If I have more information I can try your solution. Can you give me some step or information to do that? (how to create an aspx page? where save it? Where use Javascript? (onload event?)? How can i put an aspx page in a iframe?)
Thanks a lot!
Tuesday, July 20, 2010 1:23 PM -
There is actually a silverlight application that displays notes that you can follow in the "Dynamics CRM 4 Integration Unleashed" book. This displays the notes in a "nicer" fashion.
Good start to programming CRM is to download the SDK and play with the example code.
To create a note (annotation) you will have to make a call to the crm webservice (look at the SDK)
To hide a tab => crmForm.all.tabXTab.style.display="none"; where X = the number of tabs accross - 1 (the first tab on the left starts at 0)
Unfortunately it is a developer job. it may be worth investing in a CRM Partner to create this for you, it shouldnt take longer than a day to implement as it is a rather simple job.
Good Luck!
Jonathan Nachman MBSP, MCTS
Technical CRM Consultant for KMS SoftwareTuesday, July 20, 2010 1:35 PM -
you could even pass this with the example to create a new attachement possibly ?
http://rami-heleg.blogspot.com/2010/03/add-annotation-comments-files-via-modal.html
Jonathan Nachman MBSP, MCTS
Technical CRM Consultant for KMS SoftwareTuesday, July 20, 2010 1:42 PM -
I don't really understand your last post.
What is the link you are speaking about in this list? http://www.decatec.it/blogs/2010/05/21/Dynamics+CRM+Annotations.aspx
Because in this link there is no code: http://rami-heleg.blogspot.com/2010/03/add-annotation-comments-files-via-modal.html
Tuesday, July 20, 2010 3:16 PM -
second one is a possible option that you could add somewhere that would give you the ability to create notes from what ever you choose to go with as its the direct URL
Possibly if you use the sliverlight guide in the book you can use the second one as it is a URL and you wouldnt need to code any thing as that gives you the ability to create a note from the form without being in the notes section.
The code in here http://www.decatec.it/blogs/2010/05/21/Dynamics+CRM+Annotations.aspx will give you the examples to create it (as i mentioned, it would all be explained in the sdk)Jonathan Nachman MBSP, MCTS
Technical CRM Consultant for KMS SoftwareTuesday, July 20, 2010 3:18 PM -
A possible workaround is to teach the user to select the URL (instead of clicking on it) and click on an alternative toolbar / inline toolbar button that retrieves the user selection (the URL possibly) and uses it if it’s a link.
The following post http://mscrm4ever.blogspot.com/2009/10/crm-40-creating-inline-toolbar-and.html describes the method necessary to add an inline button. You can add a new section above the notes tab add the new_openurl place holder attribute to it. (see link above for explanation). The JS below is the actual implementation.
The merit of using this method, although easy to implement, is that it’s unsupported.
Cheers.
function OpenSelectedUrl()
{
//ref notes tab
var NotesIframe = document.all.notescontrol.contentWindow;
//grab selected text
var SelectedUrl = NotesIframe.document.selection.createRange().text;
var r = new RegExp("((http|https)(:\/\/))([a-zA-Z0-9]+[.]{1}){2}[a-zA-z0-9]+(\/{1}[a-zA-Z0-9]+)*\/?|","gi");
//check if it's a valid url
var result = r.exec(SelectedUrl);
if (result.input != "" && result.input == result[0])
{
window.open(SelectedUrl);
}
}
function OnCrmPageLoad()
{
window.NotesToolbar = new InlineToolbar("new_openurl");
NotesToolbar.AddButton("btnOpenLink","Open Selected Url","25%",OpenSelectedUrl);
}
GI CRM Blog * GI Website- Proposed as answer by DavidBerryMVP, Moderator Tuesday, July 20, 2010 6:36 PM
Tuesday, July 20, 2010 3:31 PM -
Hi Adi,
I try your workaround and it works fine! So thank you very much ;-)
I think it's the simplest and the easiest solution to have clickable URL for the users.
Do you know if it's possible to change the display of a note? I mean remove the first line by example (title: Note created on ....) to have a better display?
Thank you for your detailed explanation, the screenshot, and the code :-)
Wednesday, July 21, 2010 9:25 AM -
A possible quick and dirty solution is to change the functionality above to one that builds an html section for each annotation.
It’s fair to say that this solution is much more risky and if there was ever a line between good unsupported and bad unsupported this is definitely bad. Here is a working example…
function OnCrmPageLoad()
{
window.NotesToolbar = new InlineToolbar("new_openurl");
NotesToolbar.AddButton("btnShowLinks","Show Links","15%",OpenSelectedUrl);
}
function OpenSelectedUrl()
{
var NotesIframe = document.all.notescontrol.contentWindow;
var Annotations = NotesIframe.document.getElementsByTagName("TextArea");
for(var i = 0; i < Annotations.length ; i++)
{
var Note = Annotations[i];
var NoteLink = Note.Link;
if (NoteLink == null)
{
NoteLink = NotesIframe.document.createElement("SPAN");
NoteLink.style.cssText = "border-top:1px solid gray;line-height:22px;width:100%;background-color:pink";
Note.Link = NoteLink;
Note.parentElement.appendChild(NoteLink);
}
NoteLink.innerHTML = UrlToLink(Note.innerText);
}
}
function UrlToLink (text)
{
if( !text ) return text;
text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,
function(url)
{
nice = url;
if( url.match('^https?:\/\/') )
{
nice = nice.replace(/^https?:\/\//i,'')
}
else
{
url = 'http://'+url;
}
return '<a style="text-decoration:underline;color:blue;" target="_blank" rel="nofollow" href="'+ url +'">'+ nice +'</a>';
});
return text;
}
OnCrmPageLoad();
GI CRM Blog * GI Website- Marked as answer by DavidJennawayMVP, Moderator Thursday, August 5, 2010 3:40 PM
Wednesday, July 21, 2010 12:24 PM -
*Waves fist at the air* I was working on a function that turned the TextArea into a Div, which would show HTML, but also allow you to change it back to a TextArea with a double-click for editing. You beat me to the punch, Adi! I hereby bow in your general direction... AGAIN .
I think you did the right thing, though. Your code shouldn't be too much of a security risk, as mine would have been. As far as your comical distinction between good and bad unsupported goes, I'm glad to see you jumping in the mix with us "bad" guys for once. ;)
Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.comWednesday, July 21, 2010 6:02 PMModerator