1

We have added a javascript calendar to a page otherwise coded within ExactTarget using AMPscript.The calendar is fullcalendar.js and was impressed how easily it worked to create our lists of events. Challenges of course appeared only when connecting to real data where parenthesis used in a text description field are being seen in the javascript as function indicators and breaking the script (ie. no calendar appearing). I'll be honest that I have very little experience in breaking characters and don't know where to start.

My guess here is that somewhere within the javascript I'll need to insert something that indicates "When you read this "(" replace with "(" but that's a ballpark guesstimate. I may also post to a fullcalendar.js zone in Stack but didn't see a lot of activity there.

$('#calendar').fullCalendar({
eventSources: [
{
events: [ // put the array in the `events` property
%%[
FOR @i = 1 to RowCount(@rows) do
SET @row = Row(@rows, @i)
SET @evID = Field (@row, "evID")
SET @Name = Field(@row, "Name")...
]%%
            {
                title  : '%%=v(@Name)=%%',
    url: 'http://pages.info.site.com/details/?name=%%=v(@Name)=%%&eventGUID=%%=v(@eventGUID)=%%'
            },
            %%[ next @i ]%%
        ],

    }

Now if the VAR set for @Name has a (parenthesis) in it, when the code is brought to the client browser it obviously will interpret that as part of the javascript and fails. Might be other alternatives such as encoding the text field? As always hoping for something easy to comprehend and implement but not expecting that has to be the case.

I think this is the JS object representing an event below.

{
title  : 'What's new in Software (SELECTdetails 4)',
start  : '6/26/2014 12:00:00 AM',
url: 'http://pages.info.events.com/details/?name=What's new in Software (SELECTdetails 4)?&eventGUID=dfb1d3db-3aad-4eb8-ae0a-5b05f92fc7fd'
},

The current pseudo solution is (as noted below) that the problem was not the parenthesis but rather an apostrophe which was placed in the database event title as a ' mark. This needed to be eliminated. The line added to the code to accomplish this uses replace() see here:

SET @Name1 = Field(@row, "Name")
SET @Name =Replace(@Name1,"'"," i")

What is being done is to replace ' with []i so the word "what's" will now appear as what is. Tried replacing with ’ (curly apostrophe) which would be preferable but now what appears injt he fullcalendar,js element is what’ instead of what's. Because of usage though I know this needs more improvement to be fully resolved but at least the calendar displays.

6
  • Can you explain the data source and how you are populating the events in your calendar?
    – Jon Sakas
    Jun 2, 2014 at 16:43
  • The data source is an ExactTarget dataExtension. Each event in the calendar is a record (row) within that table and each has various data fields available. I'm going to add some of the code above which may help illustrate this. So I set the variables above the script for the calendar and call to them from within the javascript. That is where an even with (parenthesis) gets confused for bad code.
    – Jonny Shaw
    Jun 2, 2014 at 18:31
  • Are you trying to use AMPscript with client-side JS code, or your data literally has parenthesis in it? Some pseudo-code that gives us an idea would be super helpful. Jun 2, 2014 at 18:44
  • Yes Kelly J., I added some code above it's client side javascript featuring AMPscript set within (largely to use variable names for event items)
    – Jonny Shaw
    Jun 2, 2014 at 18:56
  • Do you have a sample of the javascript object that it outputs? Jun 2, 2014 at 19:28

3 Answers 3

4

The issue is not because of the parenthesis, its because you are closing the string too early with an apostrophe in the title of your event.

title  : 'What's new in Software (SELECTdetails 4)',

The quick fix is just to escape the apostrophe's in the string when you set the title variable:

SET @Name = Replace(Field(@row, "Name"),"'","\'")

You probably also want to encode the URL because it's likely going to create an error as well:

SET @URL = URLEncode(Field(@row, "URL"))
1

The "\" ought to work. I've used it many times successfully. So "(" would become "\("

And I had to use a double backlash to escape the backslash to get it to show up !

8
  • Yes it "should" I'm trying to locate a spot within the code where that would be placed and don't really know how to place it. Is it a standard javascript code for replace, replacewith or escape?
    – Jonny Shaw
    Jun 2, 2014 at 16:07
  • Please post your code.
    – Timothy
    Jun 2, 2014 at 17:05
  • I would but I'm not even sure what part to post. The "code" is largely from fullcalendar.js which is about 6000 lines.My guess here is that one of the variables within the javascript is placing my "@name" VAR from AMPscript within it's VAR for "$Title" and within that I need to make a note to replace any ( with ( and ) with ). I've been reviewing the 6000 lines. Hope to be back with something soon!
    – Jonny Shaw
    Jun 2, 2014 at 18:28
  • ...but I did add something above which may help... making me think perhaps I can add the break lines in as a part of setting the variables...
    – Jonny Shaw
    Jun 2, 2014 at 19:00
  • That's exactly right, they should be part of the variable.
    – Timothy
    Jun 2, 2014 at 19:09
-1

The comments below all pointed me in the correct direction but turns out the final issues was that the problem wasn't parenthesis as suspected but was instead a ' mark on an event name. The name of the item begtan with "What's New" and using the straight tic instead of a curled apostrophe was breaking the script! Once we applied the "Replace()" function to elimiate that mark, the script runs as intended and fullcalendar rendered a calendar grid as expected. Will post the code correction above as an edit.

4
  • 1
    My answer was correct and did not require you to change the event name in order to display it. Not sure if you saw that or not.
    – Jon Sakas
    Jun 3, 2014 at 16:13
  • I apologize @jsakas, I'd tried using the /escape previously but was adjusting the wrong character. Your solution is in fact 100% correct as is Timothy's, I will also review the URL encoding though it seems fine in FF I wouldn't be surprised if the links may not work everywhere without encoding. thank you.
    – Jonny Shaw
    Jun 3, 2014 at 17:40
  • No worries man! Just wanted to make sure you saw it. Thanks.
    – Jon Sakas
    Jun 3, 2014 at 18:53
  • 1
    And glad I did as having the /' is much preferred to changing the word itself.
    – Jonny Shaw
    Jun 3, 2014 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .