KMJO
KMJO

Reputation: 95

Google Apps Script Calendar Description - Line break

I would like to separate the description of a calendar event onto different lines. At the moment I am retrieving responses from a Form to populate the description field. I'd like each variable description to be on a different line

I have looked at the article How to escape JSON string? but as my responses vary as the form responses differ (and the fact I am at a beginner level) I can't work out a way to achieve it.

 function CreateEvent() {
 var vSS = SpreadsheetApp.getActiveSpreadsheet();
 var vS = vSS.getActiveSheet();  
 var vBooker = vS.getRange("B2").getValue();
 var vStartDate = vS.getRange("C2").getValue();
 var vEndDate = vS.getRange("D2").getValue();  
 var calendar = CalendarApp.getCalendarById(
 '[email protected]');
 var vlocation = vS.getRange("E2").getValue();
 var vVolume = vS.getRange("F2").getValue();
 var vVolumeOther = vS.getRange("G2").getValue();
 var vBusiness = vS.getRange("H2").getValue();
 var vBusinessOther = vS.getRange("I2").getValue();
 var vPhotographer = vS.getRange("J2").getValue();
 var vPhotographerOther = vS.getRange("K2").getValue();
 var advancedArgs ={description: ('Volume of images required = ' + vVolume + ' If Other = ' + 
         vVolumeOther + ' Project Business Area = ' + vBusiness + ' If Other = ' + vBusinessOther  
         + ' Photographer Name = ' + vPhotographer + ' If Other = ' +  vPhotographerOther), 
         location: vlocation, sendInvites:true}

 var event =  calendar.createEvent('Booked by ' + vBooker,
 new Date(vStartDate),
 new Date(vEndDate),
      advancedArgs);
   Logger.log('Event ID: ' + event.getId());

Upvotes: 1

Views: 3008

Answers (1)

Serge insas
Serge insas

Reputation: 46802

The solution is much simpler than you think... Description is a text field, you can use \n to add new line in text.

Test code below + resulting event

function testCreate(){
  var calendar = CalendarApp.getCalendarsByName('test_agenda')[0];
  var advancedArgs ={description: ('Volume of images required = ' + 'vVolume' + '\nIf Other = ' + 
         'vVolumeOther' + '\nProject Business Area = ' + 'vBusiness' + '\nIf Other = ' + 'vBusinessOther'  
         + '\nPhotographer Name = ' + 'vPhotographer' + '\nIf Other = ' +  'vPhotographerOther'), 
         location: 'vlocation', sendInvites:true}

 var event =  calendar.createEvent('Booked by ' + 'vBooker',
 new Date(),
 new Date(new Date().getTime()+3600000),
      advancedArgs);
}

enter image description here

Upvotes: 1

Related Questions