javascript: add string into another string at a specific location?

  • 1
  • Question
  • Updated 4 years ago
  • Answered
Ok, experts--

I have two rich text fields in different objects. We'll call one is InteractionNote__c on the Interactions object, and the other CaseNotes__c, on the Case object. Interaction is a child of Case.

CaseNotes__c is a bulleted list of all of the InteractionNote__c fields from all of the Interactions in the Case.

Say that currently Case has three interactions, and CaseNotes__c looks like this:

<ul>
<li>Note 1</li>
<li>Note 2</li>
<li>Note 3</li>
</ul>

I need to write a script that will take the value of InteractionNote__c when a new interaction is saved (call it 'New Note 4'), and dump it into CaseNotes__c so that the result is:

<ul>
<li>Note 1</li>
<li>Note 2</li>
<li>Note 3</li>
<li>New Note 4</li>
</ul>
I think I need some jQuery to find the last </ul> and add 
'<li>' + InteractionNote__c + '</li> 
before it. Or find the last </li> and add that after it?

Or some tricky javascript string functions?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Interesting. Why do you want to store the notes twice? Could you instead use a template based on the Interaction model to render InteractionNote__c? Surround the merge field in a DIV and they'll appear one per line rather elegantly. Or am I missing something?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
A field editor will accomplish the same thing.  It will repeat once per list item.  It can also be styled with custom styling - so you can get the look you want.  In both cases you will have to apply some custom CSS styling to get precisely the look you want. 
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Is there a way to skip blank fields in this scenario?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Nevermind... simple model condition. :)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Good to hear. 
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
A follow-up, for anyone in the same boat:

The condition turned out not to be quite as simple as I expected: https://community.skuidify.com/skuid/topics/model-condition-rich-text-field-null-not-working