Cireson Partners, Customers and Community members share your customizations and examples here to help benefit the community as a whole to earn Kudos and badges.

DISCLAIMER

All files and projects located here are provided and come "as-is" and without any warranty or support. Use at your own risk. Your use of Community Uploads is subject to our Terms of Use.

Cireson does not and will not support or maintain these enhancements, extensions, and scripts.

For Team Cireson uploads click here.

(small) Date Created, Last Modified and Resolved on WI forms

Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Advanced IT Monkey ✭✭✭
This is a very small piece of code, which is based on an idea and design by @Adrian_Mataisz (upvote his feature request here, if you want to have this OotB) and with the help of @Tom_Hendricks. Thanks for the idea and help! I thought I would post here for visibility, for anyone who is missing this info.

It adds the Created date, Last Modified date and Resolved date to the head line on IR forms (see the bottom of this post for other classes), like this:

The code code should be placed in custom.js and custom.css respectively:

custom.js
app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
   //bind a function to the form ready event
  formObj.boundReady(function () {

    // Convert dates to locale if they are not empty
    var createdDate = viewModel.CreatedDate ? (new Date(viewModel.CreatedDate)).toLocaleString() : '--';
    var lastModified = viewModel.LastModified ? (new Date(viewModel.LastModified)).toLocaleString() : '--';
    var resolvedDate = viewModel.ResolvedDate ? (new Date(viewModel.ResolvedDate)).toLocaleString() : '--';
   
    // Build div with dates
    var datesDiv = '<div class="headingFields"><span class="headingFieldLabel">Created:</span>' + createdDate +
                '<span class="headingFieldLabel">Last Modified:</span>' + lastModified +
                '<span class="headingFieldLabel">Resolved:</span>' + resolvedDate + '</div>';

    // Add div to heading
    $('div.panel-heading').first().append(datesDiv);
  });

  return;
});

custom.css
/* WI dates in heading */
div.headingFields{
  float: right;
  font-size: 14px;
}

span.headingFieldLabel{
  font-weight: bold;
  padding-left: 10px;
  padding-right: 5px;
}

For other classes, replace 'Incident' on line 1 in custom.js with e.g. 'ServiceRequest' and change the 2 x 'viewModel.ResolvedDate' with 'viewModel.CompletedDate' on line 8.

The original feature requests includes adding information about Created By, Last Modified By and Resolved By, but even though I can find CreatedBy quite easily, the two other properties are not set on the IR object itself (I can't find them at least), so it would require fetching the object through the API. I feel like this approach would be to heavy simply to display that information, so I have not included any of the "by" fields. If anyone is interested in those fields, please say so, and maybe we can have a look at it anyways.

Comments

  • fe_fefe_fe Customer IT Monkey ✭
    I actually just implemented this solution for SR's and IR's. Seems to work great. Thanks!
  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Advanced IT Monkey ✭✭✭
    @fe_fe
    That's good to hear, I'm happy to help! 
  • Adrian_MataiszAdrian_Mataisz Customer Advanced IT Monkey ✭✭✭
    Thank you @Konstantin_Slavin-Bo for providing us this code.  If I want to add Created By, What lines I have to add?

    Created By is helpful to see when an analyst created a WI on behalf of another user. 
  • Jeff_LangJeff_Lang Customer Advanced IT Monkey ✭✭✭
    to get the name of the person creating the item on there, you could try replacing
    var datesDiv = '<div class="headingFields"><span class="headingFieldLabel">Created:</span>' + createdDate + '<span class="headingFieldLabel">Last Modified:</span>' + lastModified + '<span class="headingFieldLabel">Resolved:</span>' + resolvedDate + '</div>';
    with
    var datesDiv = '<div class="headingFields"><span class="headingFieldLabel">Created:</span>' + createdDate + ' by ' + viewModel.CreatedWorkItem.DisplayName + '<span class="headingFieldLabel">Last Modified:</span>' + lastModified + '<span class="headingFieldLabel">Resolved:</span>' + resolvedDate + '</div>';
    this should add "by *name*" after the created date
    NB *name* being the name of the person who created the item



  • Jeff_LangJeff_Lang Customer Advanced IT Monkey ✭✭✭
    for those interested in getting the Resolved by User, this appears to be able to be displayed on incidents by using viewModel.RelatesToTroubleTicket.DisplayName

  • Jeff_LangJeff_Lang Customer Advanced IT Monkey ✭✭✭
    Primary Owner can also be displayed using viewModel.RelatesToIncident.DisplayName

  • Konstantin_Slavin-BoKonstantin_Slavin-Bo Customer Advanced IT Monkey ✭✭✭
    Looks good @Jeff_Lang, thanks for your input!
  • Adrian_MataiszAdrian_Mataisz Customer Advanced IT Monkey ✭✭✭

    I tried to implement this over the weekend with Created By option and IR created via email wouldn't load when trying to open the WI.  Any ideas how to fix that?

  • Jeff_LangJeff_Lang Customer Advanced IT Monkey ✭✭✭
    @Adrian_Mataisz
    We've been using this without issues, and do show the CreatedBy without any issues, including on Incidents created via the Exchange Connector.

    NOTE: The mailbox our exchange connector uses is associated with a generic user account, and it is this generic AD account that it puts in the CreatedBy, The generic AD Account also has the email address put into the e-mail field in the AD aaccount.  If it is not setup this way then i'm not sure it can associate the created by user correctly

    Here is the Incident Code we are using

    app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
    formObj.boundReady(function () {
    // Convert dates to locale if they are not empty
    var createdDate = viewModel.CreatedDate ? '<span class="headingFieldLabel">Created:</span>' + (new Date(viewModel.CreatedDate)).toLocaleString() : ' ';
    var createdBy = viewModel.CreatedWorkItem ? ' (By: ' + viewModel.CreatedWorkItem.DisplayName + ')' : ' ';
    var lastModified = viewModel.LastModified ? '<span class="headingFieldLabel">Last Modified:</span>' + (new Date(viewModel.LastModified)).toLocaleString() : ' ';
    var resolvedDate = viewModel.ResolvedDate ? '<span class="headingFieldLabel">Resolved:</span>' + (new Date(viewModel.ResolvedDate)).toLocaleString() : ' ';

    var datesDiv = createdDate + createdBy + lastModified + resolvedDate;
    var headingDiv = '<div class="headingFields">' + datesDiv + '</div>';
    $('div.panel-heading').first().append(headingDiv);
    });
    return;
    });

    and the CSS we are using as well (just in case :))
    /* WI dates in heading */
    div.headingFields{
    float: right;
    font-size: 14px;
    }

    span.headingFieldLabel{
    font-weight: bold;
    padding-left: 10px;
    padding-right: 5px;
    }




  • Adrian_MataiszAdrian_Mataisz Customer Advanced IT Monkey ✭✭✭
    @Jeff_Lang Thank you Jeff, We have the user account for the exchange connector setup the same way as you describe. I'll try again with your code. Thank you!
  • Tom_HendricksTom_Hendricks Customer Ninja IT Monkey ✭✭✭✭
    This cut out a lot of trips to the History tab for our users. 

    I wanted to share a quick modification I made, to let it support whichever date/time localization the user selects:

    // Convert dates to locale if they are not empty

    var createdDate = viewModel.CreatedDate ? new Date(viewModel.CreatedDate).toLocaleString(session.user.Preferences.Culture.IetfLanguageTag) : '--';
    var lastModified = viewModel.LastModified ? new Date(viewModel.LastModified).toLocaleString(session.user.Preferences.Culture.IetfLanguageTag) : '--';
    var resolvedDate = viewModel.ResolvedDate ? new Date(viewModel.ResolvedDate).toLocaleString(session.user.Preferences.Culture.IetfLanguageTag) : '--';

Sign In or Register to comment.