This simple script shows how detect a file being added and then send it to a Job Reviewer - the Job Reviewer in this case is set based on an Attribute on the parent job.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contracts.Data;
namespace ScriptExample
{
/// <summary>
/// A script to send an email to the Job Reviewer after a file is added
/// </summary>
public class Script : SynergyServerScripting.ServerEventScript
{
/// <summary>
/// Execute after a file is added - find the project reviewer and send them email
/// </summary>
/// <param name="file_id">the id of the new file</param>
/// <param name="change_data">information about the file change</param>
/// <param name="database">the database connection</param>
/// <param name="user_id">the id of the user who made the change</param>
/// <param name="client">the client comms channel</param>
/// <param name="client_event_id">the client event</param>
/// <returns>the operation response</returns>
public override Contracts.Responses.OperationResponse OnAfterFileAdd(Contracts.Data.EntityID file_id, Contracts.Data.FileChangeData change_data, Contracts.Databases.IDatabase database, Contracts.Data.EntityID user_id, Contracts.ServiceContracts.IClient client, long client_event_id)
{
// what project did this belong to?
EntityID project_id = SynergyServerScripting.Entities.File.GetFileProject(file_id, database);
if (project_id == null)
return Contracts.Responses.OperationResponse.Error(client_event_id, "Unable to find project!");
// find the Project Reviewer attribute
AttributeValue value = SynergyServerScripting.Entities.Project.GetProjectAttributeValue(project_id, "Job Reviewer", database);
if (value == null)
return Contracts.Responses.OperationResponse.Error(client_event_id, "Project reviewer not set!");
object attrib_val = value.Value;
ContactInfo reviewer = null;
if (value is AttributeContactValue)
{
reviewer = attrib_val as ContactInfo;
}
if (reviewer == null)
return Contracts.Responses.OperationResponse.Error(client_event_id, "Job reviewer not set!");
// get the user info object for our current user
ContactInfo contact = SynergyServerScripting.Entities.Contact.GetContactInfo(user_id, false, database);
// get the file info for the new file
FileInfo file = SynergyServerScripting.Entities.File.GetFileInfo(file_id, false, database);
// prepare and send an email
List <ContactInfo> recipients = new List<ContactInfo>();
recipients.Add(reviewer);
var email_template = new EmailTemplate(EmailTemplateCategory.Custom, "FileAdded", "A new file has been added", "A new file (" + file.path + ") has been added!");
SynergyServerScripting.Entities.Emailer.SendEmail(email_template, recipients, new List<ContactInfo>(), false);
return new Contracts.Responses.OperationResponse(client_event_id);
}
}
}
This language is not supported or no code example is available.