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

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 and add

'<li>' + InteractionNote__c + '</li> 

before it. Or find the last and add that after it?

Or some tricky javascript string functions?

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?

Nice idea, Glenn. I’ll look into it. In some situations I won’t have the Interactions model on the page, so I would have to add it. Although, I should probably use a page include since I have to replicate this across multiple pages.

To clarify, a field editor on the Interactions model would accomplish the same thing, yes? But perhaps it wouldn’t look quite so nice.

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. 

Is there a way to skip blank fields in this scenario?

Nevermind… simple model condition. :slight_smile:

Good to hear. 

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