-
Notifications
You must be signed in to change notification settings - Fork 0
Scenario Case Customization
Craig Jennings edited this page Sep 24, 2014
·
1 revision
This example demonstrates, code centric, look at changes to the baseline Agent required to add custom fields to the code responsible for creating, editing, and showing a case.
CreateCaseEndpoint.cs
[AllowRole(new[] { CasePermission.CanCreate })]
public AjaxContinuation post_support_create_kase(CreateCaseRequest request)
{
var toolkit = _session.CreateSupportToolkit();
var contact = _contactBuilder.GetOne(request.Contact.Value);
if (contact == null)
{
return _continuation.ForError("Contact", "", new[] { UserMessageKeys.ContactDoesNotExist });
}
var setup = new CreateCaseSetup(request.Site, contact.FirstName, contact.LastName, contact.Phone)
{
Title = request.Title,
CaseType = request.Type,
Priority = request.Priority,
Severity = request.Severity
};
setup.AdditionalFields.Append("x_text", AdditionalFieldType.String, request.CustomText);
setup.AdditionalFields.Append("x_service_type", AdditionalFieldType.String, request.ServiceType);
setup.AdditionalFields.Append("x_date", AdditionalFieldType.String, request.CustomDate);
setup.AdditionalFields.Append("x_case2x_language", AdditionalFieldType.String, request.LanguageDatabaseIdentifier);
/// ...
public class CreateCaseRequest : IApi
{
[Required, SchemaField("case", "title")]
public string Title { get; set; }
[Required] // contact objid from contact picker
public int? Contact { get; set; }
[Required] // site id from site picker
public string Site { get; set; }
public string Text { get; set; }
public string Type { get; set; }
public string Priority { get; set; }
public string Severity { get; set; }
//new custom fields
public string CustomText { get; set; }
public string ServiceType { get; set; }
public DateTimeOffset CustomDate { get; set; }
public int LanguageDatabaseIdentifier { get; set; }
}EditCaseEndpoint.cs
[AllowRole(new[] { CasePermission.CanEdit })]
public AjaxContinuation post_support_cases_edit(CasePostRequest request)
{
var toolkit = _session.CreateSupportToolkit();
var kase = _caseAssembler.Get(request.Id);
//Detect if the site part is being cleared.
var sitePartObjid = request.SitePartDatabaseIdentifier;
if (sitePartObjid < 1 && kase.SitePart != null)
{
sitePartObjid = -999;
}
var updateCaseSetup = new UpdateCaseSetup(request.Id)
{
Title = request.Title,
Priority = request.Priority,
Severity = request.Severity,
CaseType = request.Type,
SitePartObjid = sitePartObjid
};
updateCaseSetup.AdditionalFields.Append("x_text", AdditionalFieldType.String, request.CustomText);
updateCaseSetup.AdditionalFields.Append("x_service_type", AdditionalFieldType.String, request.ServiceType);
updateCaseSetup.AdditionalFields.Append("x_date", AdditionalFieldType.String, request.CustomDate);
updateCaseSetup.AdditionalFields.Append("x_case2x_language", AdditionalFieldType.String, request.LanguageDatabaseIdentifier);
/// ...
public class CasePostRequest : IApi
{
[Required]
public string Id { get; set; }
[Required, SchemaField("case", "title")]
public string Title { get; set; }
[Required] // contact id from contact picker
public int Contact { get; set; }
[Required] // site id from site picker
public string Site { get; set; }
public int SitePartDatabaseIdentifier { get; set; }
public string Type { get; set; }
public string Priority { get; set; }
public string Severity { get; set; }
[Required]
public string Status { get; set; }
//custom fields
public string CustomText { get; set; }
public string ServiceType { get; set; }
public DateTimeOffset CustomDate { get; set; }
public int LanguageDatabaseIdentifier { get; set; }
}ShowCaseModel.cs
public class ShowCaseModel
{
public string Id { get; set; }
public string Title { get; set; }
// ... elided for brevity
public string LinkedSolutionId { get; set; }
public int MaxRequestLength { get; set; }
//custom fields
public string CustomText { get; set; }
public string ServiceType { get; set; }
public DateTimeOffset CustomDate { get; set; }
public Language Language { get; set; }
}
public class ShowCaseMap : ModelMap<ShowCaseModel>
{
private readonly ICurrentSDKUser _currentUser;
private readonly IListCache _listCache;
public ShowCaseMap(IListCache listCache, ICurrentSDKUser currentUser)
{
_listCache = listCache;
_currentUser = currentUser;
}
protected override void MapDefinition()
{
FromView("qry_case_view")
.Assign(d => d.Id).FromIdentifyingField("id_number")
.Assign(d => d.Status).BasedOnFields("condition", "status").Do(fields => LookupStatus(fields, _listCache))
.Assign(s => s.Type).BasedOnField("type").Do(type => _listCache.GetLocalizedTitle(ListNames.CaseType, type))
.Assign(s => s.Severity).BasedOnField("severity").Do(severity => _listCache.GetLocalizedTitle(ListNames.Severity, severity))
.Assign(s => s.Priority).BasedOnField("priority").Do(priority => _listCache.GetLocalizedTitle(ListNames.Priority, priority))
.Assign(d => d.DatabaseIdentifier).FromField("elm_objid")
.Assign(d => d.Title).FromField("title")
.Assign(d => d.Condition).BasedOnField("condition").Do(StringExtensions.GetTerseCondition)
.Assign(d => d.IsInQueue).BasedOnField("condition").Do(condition => IsInQueue(condition))
.Assign(d => d.WasForwardedToQueue).BasedOnField("condition").Do(condition => WasForwardedToQueue(condition))
.Assign(d => d.OwnerLoginName).FromField("owner")
.ViaAdhocRelation("elm_objid", "case", "objid", view => view
//custom fields mapped below
.Assign(d => d.CustomDate).FromField("x_custom_date")
.Assign(d => d.CustomText).FromField("x_custom_text")
.Assign(d => d.ServiceType).FromField("x_service_type")
.MapOne<Language>().To(d=>d.Language).ViaRelation("x_case2x_language" , lang => lang
.Assign(d => d.Name).FromField("name")
.Assign(d => d.Code).FromField("code")
.Assign(d => d.Description).FromField("description")
)
// .... the rest of the map belowTODO Add snippets from the front end templates responsible for rendering the show, edit and create case models.
We hope you enjoyed this helpful Agent training document. If you see an error or omission please feel free to fork this repo to correct the change, and submit a pull request. Any questions? Contact Support.