Home General Discussion

creating an action log entry with javascript

Jarrett_FaulkJarrett_Faulk Customer IT Monkey ✭
Hello,

I am attempting to create an action log entry as part of a custom task.  I get an undefined error when attempting to push the new action log entry using the .push() function in the AppliesToTroubleTicket object.  Any guidance would be appreciated.

Best Answer

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭
    Answer ✓

    Hi,

    could you please try to change the following line:

     AppliesToTroubleTicket.ActionLog.push.apply(newActionLog);

    to:

    pageForm.viewModel.AppliesToTroubleTicket.push(newActionLog);

    this seems to be working (latest portal Version 8.2 / scsm 2016)


    regards



Answers

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hello,

    if possible - could you please post the js script - it might be easier for tracking down the problem :-)

    regards

  • Jarrett_FaulkJarrett_Faulk Customer IT Monkey ✭
    edited January 2018
    @Roland_Kind I found this script in the Knowledge Base and it just so happens to do exactly what I need.  I have some experience with Javascript but not to this level.  The bold area is the line that the debug tools are pointing to as the problem.  Thanks for looking at this.

    app.custom.formTasks.add('Incident', "Resolve Incident", function (formObj, viewModel) {
        //use require js to load the template first
        require(["text!/CustomSpace/template.html"], function (template) {
            //include enumpicker controller
            var enumPicker = require("forms/fields/enum/controller");
            //make a jQuery obj
            cont = $(template);
            //create a view model to handle the UX
            var _vmWindow = new kendo.observable({
                comment: "",
                okEnabled: false,
                charactersRemaining: "4000",
                textCounter: function () {
                    var maximumLength = 4000;
                    var val = this.comment.length;
                    (val > maximumLength) ? this.comment.substring(0, maximumLength) : this.set("charactersRemaining", maximumLength - val);
                    (val > 0) ? this.set("okEnabled", true) : this.set("okEnabled", false);
                },
                saveStatus: function () {
                    //set new status
                    viewModel.Status.set("Name", "Resolved");
                    viewModel.Status.set("Id", "2b8830b6-59f0-f574-9c2a-f4b4682f1681");
                    //set resolution description
                    viewModel.set("ResolutionDescription", this.get("comment"));
                    //set action log
                    var newActionLog = {
                        EnteredBy: session.user.Name,
                        Title: localization.Analyst + " " + localization.Comment,
                        IsPrivate: false,
                        EnteredDate: new Date().toISOString().split(".")[0],
                        LastModified: new Date().toISOString().split(".")[0],
                        Description: this.get("comment"),
                        Image: app.config.iconPath + app.config.icons["comment"],
                        ActionType: "AnalystComment"
                    }
                    //beta method
                    AppliesToTroubleTicket.ActionLog.push.apply(newActionLog);
                },
                okClick: function () {
                    this.saveStatus();
                    customWindow.close();
                },
                cancelClick: function () {
                    customWindow.close();
                }
            });
            //create the kendo window
            customWindow = cont.kendoWindow({
                title: "Resolve Incident",
                resizable: false,
                modal: true,
                viewable: false,
                width: 500,
                height: 400,
                close: function () {
                },
                activate: function () {
                    //on window activate bind the view model to the loaded template content
                    kendo.bind(cont, _vmWindow);
                }
            }).data("kendoWindow");
            //more functions
            var buildEnumPicker = function (container, properties, vmModel) {
                enumPicker.build(vmModel, properties, function (enumControl) {
                    container.html(enumControl);
                    app.controls.apply(container, { localize: true, vm: vmModel, bind: true });
                }, properties);
            }
            var resolutionProperties = {
                PropertyName: "ResolutionCategory",
                PropertyDisplayName: "ResolutionCategory",
                Required: true,
                EnumId: "72674491-02cb-1d90-a48f-1b269eb83602"
            };
            buildEnumPicker(cont.find('#resolutionPicker'), resolutionProperties, viewModel);
            //now open the window
            customWindow.open().center();
        });
    });
  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭
    Answer ✓

    Hi,

    could you please try to change the following line:

     AppliesToTroubleTicket.ActionLog.push.apply(newActionLog);

    to:

    pageForm.viewModel.AppliesToTroubleTicket.push(newActionLog);

    this seems to be working (latest portal Version 8.2 / scsm 2016)


    regards



  • Jarrett_FaulkJarrett_Faulk Customer IT Monkey ✭
    @Roland_Kind
    Hello,  I've come across another question concerning a similar issue as we were discussing earlier.  The script I have here works as long as the user is an analyst.  When I switch over my test user it fails on viewModel.RelatesToTroubleTicket.set statement.  I've track it down to the fact that is RelatesToTroubleTicket doesn't load for an end user until after the ticket is resolved.  Since the users i'm building this for are end users I need to load the RelatesToTroubleTicket before setting who resolved the request.  I've tried the init, set, get functions on the pageForm.viewModel but I am unable to get this to load using javascript. 

    Would you or anyone else have any insight as to how I can load this object into the view model with the script I've posted above?

    Thanks in advance.

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hi Jarrett,

    just a very quick solution - please try this - should work ;) 

    just add the following lines to your .js file


    ... (cut from your file)

    //beta method
                    pageForm.viewModel.AppliesToTroubleTicket.push(newActionLog);
        
       var newRel;
       newRel = {Name: "RelatesToTroubleTicket", RelationshipId: "f7d9b385-a84d-3884-7cde-e2c926d931a5"} ;              
        pageForm.viewModel.NameRelationship.push (newRel);
        
        pageForm.viewModel.RelatesToTroubleTicket = {
          "ClassTypeId": pageForm.viewModel.ClassTypeId,
          "BaseId": session.user.Id,
          "Id": pageForm.viewModel.Id
         };
        
        var curDate = new Date();    
        pageForm.viewModel.ResolvedDate=curDate.toISOString();


    .... (remaining part of your file)

     

    regards

    Roland

  • Jarrett_FaulkJarrett_Faulk Customer IT Monkey ✭
    edited January 2018
    @Roland_Kind

    This works exactly how i figured it would need to.  How did you find the RelationshipID.  I don't understand where this information is stored or where i can find it to try to figure these things out on my own.  Is there documentation you could point me towards?

    Thank you for all the help on this.  I just have to try to figure out how to get the selection from the enum pickers to pass the IDs back to the viewModel so it sets the correct classifications and resolution categories.
  • john_doylejohn_doyle Cireson Support Ninja IT Monkey ✭✭✭✭
    @Jarrett_Faulk

    The simplest way would be to open an Incident in your browser, then open the browser's Developer Tools and type
    pageForm.viewModel.NameRelationship
    into the Console tab.
    This will give you an object showing all the relationships mapped to the view model. Just look for the relationship you want and you will find the RelationshipId.

  • Roland_KindRoland_Kind Partner Advanced IT Monkey ✭✭✭

    Hi Jarrett,

    great :-) & depending an what you need regarding the enums pickers the following links maybe helpful:

    https://community.cireson.com/discussion/comment/11444#Comment_11444

    https://community.cireson.com/discussion/comment/4354#Comment_4354

    regards

    Roland

Sign In or Register to comment.