Calendar Event On-Click Behavior Javascript Snippet - HOW TO GET ROW ID

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I have a Calendar and I am trying to write a Javascript Snippet so that when the Calendar item is clicked, users will be redirected to another URL instead of seeing a popup. 

var params = arguments[0],$ = skuid.$;
var models = skuid.model.map();
var Appointments = models.Appointments;
var TheAppointment = Appointments.getFirstRow();
var Id = Appointments.getFieldValue(TheAppointment,'Id');
window.location = '/apex/skuid__ui?page=AppointmentDetail&Id=' + Id;


Unfortunately getFirstRow() does not work in this situation, because no matter which Calendar Item I click I get the same Record ID. 

How do I fix the Javascript so that it knows the ID of the Calendar item I am clicking on?

Thanks!
Photo of Jason Thurgood

Jason Thurgood

  • 654 Points 500 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
This should do it:

var params = arguments[0];
window.location = '/apex/skuid__ui?page=AppointmentDetail&Id=' + params.row.Id;

Event On-Click Snippets are handed several arguments, but the most helpful ones for you here are:

- event: the row that was clicked in the event source's model (same thing as row)
- row: the model row corresponding to the event that you selected
- eventSource: the Event Source object for the event you clicked on
- model: shortcut reference to the event source's model
Photo of Jason Thurgood

Jason Thurgood

  • 654 Points 500 badge 2x thumb
Zach, another question related to this snippet.    I want to redirect to different URLs based on the User's profile name.  How do I assign the Users Profile Name to a variable so I can use it in the IF statements?

Here is what I have so far, but no luck, and it's using ID's which is not ideal:

var params = arguments[0];var profile = skuid.utils.userInfo.profileid;
if(profile == '00e1a000000RWZdAAO' || '00e1a000000RcH5AAK'){
window.location =  'caminoportal/apex/skuid__ui?page=AppointmentDetail&Id=' + params.row.Id;
}
else{
    window.location =  'caminoportal/apex/skuid__ui?page=AppointmentManager&Id=' + params.row.Id;
}
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
The reason this isn't working is due to camel-casing of variable names --- profileId with Id capitalized instead of profileid ... it's always the small things :)

If you are on Banzai, you can (and should!) use profileName instead:

var params = arguments[0];
var profile = skuid.utils.userInfo.profileName;
if((profile === 'Skuid Ninja') || (profile === 'Christopher Nolan Fanboy')){

} else {

}
(Edited)
Photo of Jason Thurgood

Jason Thurgood

  • 654 Points 500 badge 2x thumb
Works like a charm.  Thanks again!
Photo of Jason Thurgood

Jason Thurgood

  • 654 Points 500 badge 2x thumb
Awesome!  Thank you so much!