Home Analyst Portal

Apply IR template to existing Incident record

Steve_BarnardSteve_Barnard Partner IT Monkey ✭

Hi,

Working with a customer who wants to replicate the task from the Service Manager console whereby you can apply an existing template to an Incident record. Eg. Open an Incident record and apply the 'Major Incident' template. Can this be accomplished in the Cireson portal?

Thanks

Steve

Best Answers

Answers

  • Geoff_RossGeoff_Ross Cireson Consultant O.G.
    Hi Steve,
    Yes, this can be done. In very brief terms, (anyone reading this let me know if you want more detail) you need to use the get templates API call, work out which one you need, then copy properties one by one to the view model and then commit it.
    Geoff
  • Steve_BarnardSteve_Barnard Partner IT Monkey ✭
    Cheers Geoff. Could you provide more detail please?
  • Magnus_AnderssonMagnus_Andersson Customer IT Monkey ✭
    Hi, im interested in this too. We have a large number of Templates that is Resolve templates. The template change the Case to Resolved and put in the Resolve text.

    So, is it alot of work to get this to work?
  • David_DarlingDavid_Darling Customer IT Monkey ✭

    Just curious if anybody has developed this functionality and is willing to share their code?  Thanks!

  • Sean_TerrySean_Terry Customer Advanced IT Monkey ✭✭✭
    We'd also be interested in this as well if the code is available.
  • Olena_PrychynaOlena_Prychyna Customer IT Monkey ✭

    Geoff, we followed your steps and this code works for us:

    custom.js:

    /* ------------------------------------------------------------------------------------------- */
    /* ----------- Incident - Apply Template ----------------------------------------------------- */
    /* - Task is available only for New incident (before it is submitted)        */
    /* - Analyst comment will be in the Incident comment field, so they can manually add it to IR */      
    /*Problems:                        */
    /*  - TemplateApplied log is created as EndUserComments, but not as ActionLog     */
    /* -------------------------------------------------------------------------------------------- */


    //show task only for New IR
    app.custom.formTasks.add('Incident', null, function (formObj, viewModel) {
     formObj.boundReady(function(){
      //If the incident is not New don't show the Apply Template task
      if(window.location.href.indexOf("Incident/New")== -1){
       $("li[class='link']:contains('Apply Template')").hide();
      }
     });
     
    });


    //Incident - Apply Template - add task
    app.custom.formTasks.add('Incident', "Apply Template", function (formObj, viewModel) { 
      var classid = "a604b942-4c7b-2fb2-28dc-61dc6f465c68";
        $.ajax({
            url: "/api/V3/Template/GetTemplates",
            data: {classId: classid},
            type: "GET",
            success: function (data) {
                console.log (data)
                //Call the loadTemplates Function and send it the PR Template Names and Id's
                loadTemplates(data);
       
            }
        });
        
      function loadTemplates (templateData){
            //use requirejs to load the HTML template first
            require(["text!/CustomSpace/customtasks.applytemplate.html"],
                function (htmlTemplate) {
                    //make a jQuery obj
                    templateObj = $(htmlTemplate);

                    //create a view model to handle the UX
        var dataItem;
                    var _vmWindow = new kendo.observable({
                        dropDownData: templateData,
                        valueChanged : function(e) {
                            dataItem = e.sender.dataItem();
                           // console.log (dataItem.Id)
                        },
                        okClick: function () {
          
                            var tempId = dataItem.Id //$("#templateselected option:selected").val();
          var tempName = dataItem.Name //$("#templateselected option:selected").text();
          
          updateIncident(tempId,tempName );
                           
                            customWindow.close();
                        },
                        cancelClick: function () {
                            customWindow.close();

                        }
                    });
                
                    //create the kendo window
                    customWindow = templateObj.kendoWindow({
                        title: "Apply Template",
                        resizable: false,
                        modal: true,
                        viewable: false,
                        width: 500,
                        height: 300,
                        close: function () {
                
                        },
                        activate: function () {
                            //on window activate bind the view model to the loaded template content
                            kendo.bind(templateObj, _vmWindow);
                        }
                    }).data("kendoWindow");
                
                    //now open the window
                    customWindow.open().center();
                }
            );
        }
     
     function updateIncident(selectedTempId, selectedTempName) {
      //selectedTemp is a json object
      var incident = pageForm.viewModel;
      //get template content and save every property into pageForm
      
      $.ajax({
              url: "/api/V3/Projection/CreateProjectionByTemplate",
              data: {id: selectedTempId, createdById: session.user.Id},
              type: "GET",
              success: function (data) {
               
                //Copy properties from Projection into current IR
                incident.set("Title",data.Title);
       
       var oldDescr='';
       if(incident.Description){oldDescr = incident.Description + '\n' ;}
       var newDescr = oldDescr + data.Description;
       incident.set("Description",newDescr);
       
       
       incident.set("Source",data.Source);
       incident.set("TierQueue",data.TierQueue);
       incident.set("HasCreatedKnowledgeArticle",data.HasCreatedKnowledgeArticle);
       incident.set("Classification",data.Classification);
       incident.set("CauseCode",data.CauseCode);
       incident.set("Impact",data.Impact);
       incident.set("Urgency",data.Urgency);
       
       //show Analyst Comment in comment field, so they can add it manually
       var commentBox = $("div[class=form-group]").find("textarea");
       commentBox.focus();
       commentBox.val(data.AppliesToTroubleTicket[0].Comment);
       
       commentBox.keyup();

      
       //add relationships 
       
       //functions-helpers
       var isDuplicate = function (idToAdd) {
        var n = false;
        $.each(boundArray, function (i, item) {
          if (item.BaseId == idToAdd) {
           n = true;
          }
         });
         return n;
        } 
       
       
        var addAffectedItem = function (baseId ) {
        if (isDuplicate(baseId)) { return; }
         $.getJSON('/ConfigItems/GetAffectedItem', { id: baseId }, function (json) {
          var item = {
           BaseId: baseId,
           DisplayName: json.DisplayName,
           Path: json.Path,
           AssetStatus: { Name: !_.isUndefined(json.AssetStatus) ? json.AssetStatus : "" },
           Status: { Name: !_.isUndefined(json.Status) ? json.Status : "" }
           };
          boundArray.push(item);
         });
        } 
       //--end of functions-helpers 
       //init incident.HasRelatedWorkItems array   - need it for incident.AppliesToTroubleTicket to work   - ?
       
       if (_.isUndefined(incident.HasRelatedWorkItems)) {
                    incident.set('HasRelatedWorkItems', new kendo.data.ObservableArray([]));  
                }
       var boundArray = incident.get('HasRelatedWorkItems');
       
        for(var i=0; i < data.HasRelatedWorkItems.length; i++){
         addAffectedItem(data.HasRelatedWorkItems[i].BaseId);
        };

       //add action logs
       //template applied - wrong log type ?
       
       incident.AppliesToTroubleTicket.push({
       "ActionType": "EndUserComment",    //not in Action Log  
       "EnteredBy": session.user.Name,
       "Title": "EndUserComment",
                "EnteredDate": new Date().toISOString().split(".")[0],
                "LastModified": new Date().toISOString().split(".")[0],
                "Description": "Template applied: " + selectedTempName,
                "Image": "/Content/Images/Icons/ActionLogIcons/recordopened/templateapplied.png",
         "LastUpdatedDisplay": null
       }); 
       
        } 
            });
     }
     

    });

  • Kenneth_McMichaelKenneth_McMichael Customer IT Monkey ✭

    Thanks for this! - I'm attempting to do this myself and it's working very well with one exception. When the Apply Template option is picked - it shows  blocks in the empty white space.

    See below

    I have tried some things to resolve but nothing has worked so far. Any ideas on why it's doing this? This happens on any browser I test it on

    thanks

  • Kenneth_McMichaelKenneth_McMichael Customer IT Monkey ✭
    edited May 2017
    Upgrading to the latest portal version - solved the above issue

    However I have been struggling to also get it to set the 'Assigned To' from the template. I added incident.set("AssignedTo",data.AssignedTo); to the custom.js but it doesn't add the data from the template.
  • Olena_PrychynaOlena_Prychyna Customer IT Monkey ✭

    To set the "Assigned To" field from template:

       
       incident.AssignedWorkItem.set("DisplayName", data.AssignedWorkItem.DisplayName);
       incident.AssignedWorkItem.set("BaseId", data.AssignedWorkItem.BaseId);

  • Karen_Bruster1Karen_Bruster1 Member IT Monkey ✭

    @Olena_Prychyna I saw your post and have a few questions.

    Where do you put the file with your code customtasks.applytemplate.html:, and where do you insert the "Assigned To" code to your code?

  • Olena_PrychynaOlena_Prychyna Customer IT Monkey ✭

    Karen_Bruster1 you should add the code into custom.js file. We have it in:  C:\inetpub\CiresonPortal\CustomSpace\custom.js

    As you see in the code the location of .html file is specified in:

     function loadTemplates (templateData){
                   require(["text!/CustomSpace/customtasks.applytemplate.html"], ...     

    so it is also in   C:\inetpub\CiresonPortal\CustomSpace\                 

  • Karen_Bruster1Karen_Bruster1 Member IT Monkey ✭

    To set the "Assigned To" field from template:

       
       incident.AssignedWorkItem.set("DisplayName", data.AssignedWorkItem.DisplayName);
       incident.AssignedWorkItem.set("BaseId", data.AssignedWorkItem.BaseId);

    @Olena_Prychyna Where in the custom.js would you add this?

    And I noticed you have this setup to work with New IR's but what if you want to use it for already Active IRs?

  • Olena_PrychynaOlena_Prychyna Customer IT Monkey ✭

    Karen_Bruster1, we tried to reproduce the Console behavior where Apply Template works only for new IR. But I think it should work for an Active IR as well.  We did not test it though.

    For that you should replace Incident/New with Incident/Edit in code:

    if(window.location.href.indexOf("Incident/New")== -1){

  • Kenneth_McMichaelKenneth_McMichael Customer IT Monkey ✭
    Has anyone tried to add Template Description to the window that pops up? It would be useful for the analysts to be able to see the description already stored in Service Manager.
  • Brad_ZimaBrad_Zima Member Advanced IT Monkey ✭✭✭

    I know this is an older post, but is there a way to have this task also apply any activities in the template?

Sign In or Register to comment.