Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

New Appointment from CS

Hi,

 

I Would like to create a button on a ticket that enables the user to create a task for his colleague that usese Sales & Marketing.

Based on some default:

- appointment type can be hardcoded like type=15 (phone out)

- Text can be hardcoded: "Look into request tab. Your Customer has a complaint"

- date is today

- contact and person is known.

 

Would such be possible from CS? And how would the script look like?

thanx!,

Niels

RE: New Appointment from CS

Hi Niels, it would look a little bit like this:

#setLanguageLevel 3;

/*
 * Oppretter en aktivitet i SuperOffice på kontakt/person som er tilknyttet saken
 * Frode, 26.feb 2011
 */

Integer ticketId = getCgiVariable("ticketId").toInteger();

if (ticketId > 0)
{
  Ticket t;
  t.load(ticketId);

  Integer personId = t.getValue("cust_id").toInteger();

  NSPersonAgent personAgent;
  NSPerson person = personAgent.GetPerson(personId);
  Integer contactId = person.GetContactId();

  print("PersonId = " +personId.toString());

  NSAppointmentAgent appAgent;
  NSAppointmentEntity newApp = appAgent.CreateDefaultAppointmentEntity();
  newApp.SetDescription("Følge opp sak " + ticketId.toString() + " (\"" + t.getValue("title") + "\") i Customer Service");

  //Set contact and person on appointment
  NSContact contact;
  contact.SetContactId(contactId);
  newApp.SetContact(contact);
  newApp.SetPerson(person);

  DateTime start;
  DateTime end;
  start.addDay(1);
  end = start.addMin(30);
  end = end.addHour(1);
  newApp.SetActiveDate(start);
  newApp.SetStartDate(start);
  newApp.SetEndDate(end);

  NSTaskListItem task;
  Integer taskId = 5; //"Oppfølging";
  task.SetTaskListItemId(taskId);
  newApp.SetTask(task);

  NSAppointmentEntity createdApp;
  createdApp = appAgent.SaveAppointmentEntity(newApp);
  print("Opprettet aktivitet med appointment_id = " +createdApp.GetAppointmentId().toString());

  Message m;
  m.setValue("ticketId", ticketId.toString());
  String soUrl = "superoffice:appointment.main.activate?appointment_id=" + createdApp.GetAppointmentId().toString() + "&edit";
  m.setValue("bodyHtml", "(Opprettet oppfølging i Sales & Marketing - <a href=\"" + soUrl + "\">klikk her</a> for å se oppfølgingen.)");
  m.setValue("author", "EJscript");
  m.save();

  if(false)
  {
    Integer ejUserId = getVariable("activeUser").toInteger();
    User u;
    u.load(ejUserId);

    Email mail;
    mail.setValue("to", "some@email.no");
    mail.setValue("subject", "ejscript knapp kjørt");
    mail.setValue("body", u.getValue("username") + " brukte opprett-avtale-fra-ej knappen for sak " + ticketId.toString());
    mail.send();
  }

  //Refresh ticket page
  setVariable("url", getProgramTicket() + "?_sf=&action=viewTableEntry&table=ticket&id=" + ticketId.toString());
}
By: Frode Lillerud 17 Oct 2013

RE: New Appointment from CS

Hi frode,

 

Thanx!!! Seems that you had this challenge as well some time ago!

The if False part is very nice too!

 

Thanx again, will go and fiddle around with it....

 

Niels

By: Niels van Broekhoven 17 Oct 2013