Override subject line with details line while creating Communication

By | July 31, 2012

Just a tricky JavaScript here. I came across one interesting scenario where I want to override the subject line with the details if the Subject line contains within the details while creating communication.
Consider the scenario, if the subject line is “This meeting is important” and the details line is “We should attend it because this meeting is important”. In this case my subject line contains within details, I want to override my subject line with my details line. To achieve this I tried the following code.
if(comm_subject != null && comm_note != null)
{
     var commNote=comm_note.toLowerCase();
    var commSubject=comm_subject.toLowerCase();
     commNote=commNote.replace(/\r\n/g, ”);
     if(commNote.search(commSubject)>=0)
     {
         comm_subject = comm_note;
     }
}