Power of Scripting - JavaScript Use Cases

Power of Scripting - JavaScript Use Cases




What is Scripting?

With new Scripting option available on all the pages of the SummitAI application (Alps), the Administrators can now write their own JavaScript, HTML, and CSS codes to customize the fields available on these pages.

SummitAI - Version

Scripting feature is introduced into the SummitAI application on few pages with the Alps release. This feature is now available on all the pages of the Application with Alps SP1 release. In the Alps release, the Admin could write JavaScript and CSS codes. With Alps SP1 release, the Administrators can write JavaScript, HTML, and CSS codes.

For more information about Scripting, see Scripting.

Why Scripting?

  • Scripting gives the power to the Administrators to write their own codes to make changes the way the organizations want.

  • The SummitAI R&D team can help the organizations in writing codes and can provide solutions to the customer requirements much faster instead of waiting for longer release cycles.

  • The JavaScript codes are executed only to the specific customer instance. No product code change is required eliminating the need to plan, develop, and test the changes.

  • The SummitAI team can focus on other customer requirements and product roadmap features instead of spending time on UI changes, which can be now easily achieved with Scripting.

Use Cases for JavaScript

#1: The Analyst should enter a business justification if the Change is not implemented as per the schedule

#6: Based on the selected Vendor under the Vendor tab of the Incident details page, there should be an option to click on a link that opens the Vendor pop up displaying the Vendor details

#11: The Manager Search control should reflect for specific drop-down values

#16: The RCA Deadline of auto-generated Problem Records (PRs) should be 4 days from the date of PR creation

#2: When an Analyst logs an Incident for an End User, the Application should prompt if an open Incident exists for that user under the same Category. This would prevent the Analyst from creating duplicate Incidents for the same user

#7: While logging Incidents, the Asset selection is mandatory. However, if there is no Asset allocated to the user, the Asset selection should become non-mandatory

#12: Every Problem Record should have a Knowledge Record linked to it

#17: Restrict few special characters in Private Log, Information, Solution, User Communication, and Description

#3: The 'Service Window' field on the Incident details page should be hidden for the Analysts. The Analysts should not change the Service Window of the Incidents

#8: The End User should have the option to select Permanent/ Temporary/ Residential Address. If any of these options are selected, there should be an option to enter the address

#13: While raising a Change Request from a Service Request only "Business Requirement" Change Type should be selected/auto- selected and grayed out. Analysts must not be able to select any other type of Change if it is requested from SR

#18: There is a Custom Field called 'Lab ID' on the LOG NEW INCIDENT page. This field should be hidden if Category is "Inquiry". However, it should be mandatory for any other Category

#4: When an Analyst logs an Incident for an End User, the Application should prompt if an open Incident exists for that user under the same Category. This would prevent the Analyst from creating duplicate Incidents for the same user

#9: The user can update various fields in a Service Request, such as Username, Date of Birth, Address, Location, etc. However, if the user selects more than two fields, the Application should display a message stating that the user cannot modify more than 2 fields  in a Service Request

#14: The Actual PIR Date should be auto-populated based on the system time at the time of PIR submission

Use Case #19: The End User has an option to select the Date of Birth in the Service Request form. Validate if the user is above 18 years from the Date of Birth and do not allow the user to select future date

#5: When a Change Request is created from a Service Request, the Description of the Change Request would be the Symptom of the Service Request. The Change Request Description should be cleared if it is created from a Service Request

#10: In the E-mail ID field, the Application should allow to enter e-mail ids, only if the e-mail id contains "@symphonysummit.com". Otherwise, it should not allow the user to submit the request

#15: While requesting for Software installation, the users should not select a date in past as the Software Installation Date

#20: When the End User rejects an Asset, an Incident should be created.

How to Inspect Elements to Find Controls?

This section provides instructions to inspect an element in the following browsers:

Microsoft Edge

To inspect elements in Microsoft Edge:

  1. Hover over the element to inspect and then press F12.
    or
    Click the

     icon (present on the top right-hand corner of the browser) > Click Developer Tools.

  1. On the Inspect window, click the 

     icon (Select the Element icon)..

  2. Take the mouse cursor to the element you want to inspect click the element. The ID of the element is displayed in the Inspect window.

Internet Explorer

To inspect elements in Internet Explorer:

  1. Hover over the element to inspect and then press F12.
    or
    Click the 

     icon (present on the top right-hand corner of the browser) > Click F12 Developer Tools.

  1. On the Inspect window, click the 

     icon (Select Element icon).

  2. Take the mouse cursor to the element you want to inspect click the element . The ID of the element is displayed in the Inspect window.

Firefox

To inspect elements in Firefox:

  1. Hover over the element to inspect and then press F12.
    or
    Click the 

     icon (present on the top right-hand corner of the browser) > Click Web Developer > Storage Inspector.

  1. On the Inspect window, click the 

     icon (Select Element icon).

  2. Take the mouse cursor to the element you want to inspect. The ID of the element is displayed in the Inspect window.

Google Chrome

To inspect elements in Google Chrome:

  1. Hover over the element to inspect and then press F12.
    or
    Click the 

     icon (present on the top right-hand corner of the browser) > Click More Tools > ClickDeveloper Tools.

  1. On the Inspect window, click the 

     icon

  2. Take the mouse cursor to the element you want to inspect. The ID of the element is displayed in the Inspect window.

Below example shows how to inspect element in Google Chrome :-



Use Cases - Details

Following are the various use cases where SummitAI has leveraged on the Scripting functionality and delivered various customer customizations

Note:

Code samples are provided for few of the use cases. For the other JavaScript codes, please contact SummitAI Support.



Use Case #1: The Analyst should enter a business justification if the Change is not implemented as per the schedule

Page: Change > New Change Record

Prerequisite: Create a custom field called "Business Justification"

JavaScript Logic: If there is a difference between "Planned Start Date/ Planned End Date" and "Actual Start Date/ Actual End Date", the custom field "Business Justification" will become mandatory when the Change Record status is Implemented.

function CMChangeRequestCustomOnSaveJS() {

    //place custom validation script here

    //return false if you dont want to submit the changes

 

  if (!fnDateValidationJS()) {

       return false;

    }

 

return true;

}

 

//***compared between planned start time & actual start time****//

 fnDateValidationJS();

 function fnDateValidationJS() {

     try {

         var lblPlannedstarttime = 'BodyContentPlaceHolder_lPlannedStartTime1',

            datPlannedstarttime = 'BodyContentPlaceHolder_txtPlanStartRlease_Time',

            lblPlannedendtime = 'BodyContentPlaceHolder_lPlannedEndTime1',

            datPlannedendtime = 'BodyContentPlaceHolder_txtPlan_End_Rlease_Time',

            lblActualstarttime = 'BodyContentPlaceHolder_lActualStartTime1',

            datActualstarttime = 'BodyContentPlaceHolder_txtActualStartTime',

            lblActualendtime = 'BodyContentPlaceHolder_lActualEndTime1',

            datActualendtime = 'BodyContentPlaceHolder_txtActual_End_Time_Release',

            lblJustification = 'BodyContentPlaceHolder_lblCF_49',

            txtJustification = 'txt_49';

 

         lblPlannedstarttime = $('#' + lblPlannedstarttime);

         datPlannedstarttime = $('#' + datPlannedstarttime);

         lblPlannedendtime = $('#' + lblPlannedendtime);

         datPlannedendtime = $('#' + datPlannedendtime);

         lblActualstarttime = $('#' + lblActualstarttime);

         datActualstarttime = $('#' + datActualstarttime);

         lblActualendtime = $('#' + lblActualendtime);

         datActualendtime = $('#' + datActualendtime);

         lblJustification = $('#' + lblJustification);

         txtJustification = $('#' + txtJustification);

 

         lblJustification.hide();

         txtJustification.hide();

 

         if (datPlannedstarttime.val().trim().length > 0 && datActualstarttime.val().trim().length > 0) {

             if (Date.parse($("#BodyContentPlaceHolder_txtPlanStartRlease_Time").val()) != Date.parse($("#BodyContentPlaceHolder_txtActualStartTime").val())) {

                 lblJustification.show();

                 txtJustification.show();

                 lblJustification.addClass('mandatoryField');

                 MarkRequiredInputs();

                 if (txtJustification.val().trim().length == 0) {

                     InitOnScreenNotification("specify " + lblJustification.text().replace('*', ''), 'warning');

                    return false;

 

                 }

             }

         }

 

       if (datPlannedendtime.val().trim().length > 0 && datActualendtime.val().trim().length > 0) {

             if (Date.parse($("#BodyContentPlaceHolder_txtPlan_End_Rlease_Time").val()) != Date.parse($("#BodyContentPlaceHolder_txtActual_End_Time_Release").val())) {

                 lblJustification.show();

                 txtJustification.show();

                 lblJustification.addClass('mandatoryField');

                 MarkRequiredInputs();

                 if (txtJustification.val().trim().length == 0) {

                     InitOnScreenNotification("specify " + lblJustification.text().replace('*', ''), 'warning');

                    return false;

                 }

             }

         }

     }

     catch (e) {

         console.log('Rule Validation error:' + e.message);

     }

     return true;

 }

 $("#BodyContentPlaceHolder_txtPlanStartRlease_Time, #BodyContentPlaceHolder_txtActualStartTime").change(function () {

     fnDateValidationJS();

 });

 

 $("#BodyContentPlaceHolder_txtPlan_End_Rlease_Time, #BodyContentPlaceHolder_txtActual_End_Time_Release").change(function () {

     fnDateValidationJS();

 });


Use Case #2: When an Analyst logs an Incident for an End User, the Application should prompt if an open Incident exists for that user under the same Category. This would prevent the Analyst from creating duplicate Incidents for the same user .

Page: Incident > New Incident for User

JavaScript Logic: Based on the Caller and the Category of the Incident, validate if there is any open Incident for that Caller under the same Category. Display a popup, which indicates that there are open Incidents for that caller under the same Category. Display the Incident IDs in the popup.

function LogNewTicketCustomOnSaveJS() {

    var InstanceCtrl = $('#BodyContentPlaceHolder_UCInstanceList_lstInstance');

    if (InstanceCtrl.val() == 'DLPL') {

              




        if(!isTicketExists_Summit())

            return false;

    }




   return true;

}







function isTicketExists_Summit() {

    var status = false;

    try {

        var CallerID1 = $('#BodyContentPlaceHolder_txtCaller'); // Caller Textbox ID

        var hdnCallerID = $('#BodyContentPlaceHolder_hdnCallerID'); // Caller hidden field ID

        var hdnCategoryID = $('#BodyContentPlaceHolder_hdnCategoryID'); // Category hidden Field ID

        var Instance1 = $('#BodyContentPlaceHolder_UCInstanceList_lstInstance');  // Instance Control ID

        var validationMsg = 'Already few open incidents are there under this category.'; //Validation Message




        var CustomAttributeNameID = $('#txt_23'); // Customer Attribute control ID

        //var CustomAttributeNameID = $('#txt_1170');

        var CustomAttributeID = 23; // Custom Attribute ID if customattribute control id is #cddl_109, 109 is attribute ID




        var Selectedcategory, selectedcustAttribute, SelectedInstance;

        var Tickets = null;

        var Counts = 0;

        var IncidentRaiseStatus; var Caller_ID = 0;

        // if caller control enabled in lognew incident check is enabled if enabled need to take caller otherwise Log in user

        if (CallerID1.length == 1) {

            var callerid = hdnCallerID.val();

            if (callerid != undefined && callerid != "" && callerid != null) {

                Caller_ID = hdnCallerID.val();

            }

            else {

                Caller_ID = UserID;

            }

        }

        else {

            Caller_ID = UserID;

        }

        console.log(Caller_ID);




        Selectedcategory = hdnCategoryID.val();

        selectedcustAttribute = CustomAttributeNameID.val();

        SelectedInstance = Instance1.val();

        /*

         * URL,User Name and password need to change

         * dynamic service name should be "Is_Category_TicketExists"

         */

        if (Caller_ID > 0 && Selectedcategory != null && Selectedcategory != "" &&  SelectedInstance != null && SelectedInstance != "") {

            var settings = {

                "async": false,

                "crossDomain": true,

                "url": "http://52.172.217.125/API/REST/Summit_RESTWCF.svc/RESTService/CommonWS_JsonObjCall",

                "method": "POST",

                "dataType": "json",

                "contentType": "application/json",

                "headers": {

                    "content-type": "application/json"




                },

                "processData": false,

                "data": "{\"ServiceName\":\"ADM_Get_DynamicWebServiceResult\",\"objCommonParameters\":{\"_ProxyDetails\":{\"Password\":\"admin@123\",\"UserName\":\"summitadmin@dlpl.com\",\"ProxyID\":0,\"ReturnType\":\"JSON\",\"OrgID\":1},\"ServiceName\":\"Is_Category_TicketExists\",\"objDynamicWebService\":{\"InputString\":\"{\\\"CustomeAttributeID\\\":\\\"" + CustomAttributeID + "\\\",\\\"categoryId\\\":\\\"" + Selectedcategory + "\\\",\\\"userID\\\":\\\"" + Caller_ID + "\\\",\\\"instance\\\":\\\"" + SelectedInstance + "\\\",\\\"CustomeAttributeValue\\\":\\\"" + selectedcustAttribute + "\\\"}\"}}}"

            }

            var Isexiststicket = $.ajax(settings).done(function (response) {

                if (response) {

                    result = response;

                    if (result.OutputObject != null && result.OutputObject.SUBROOT[0] != null) {

                        IncidentRaiseStatus = result.OutputObject.SUBROOT[0].IsTicket_Exists;

                        Counts = result.OutputObject.SUBROOT[0].Counts;

                        Tickets = result.OutputObject.SUBROOT[0].Tickets;

                        console.log(IncidentRaiseStatus, Counts, Tickets);

                        console.log('got the response');

                    }

                    if (IncidentRaiseStatus != undefined && IncidentRaiseStatus == "0") {

                        status = true;

                        console.log('status is true');

                    }

                    else if (IncidentRaiseStatus != undefined && IncidentRaiseStatus > 0) {

                        status = false;

                    }

                    else if (IncidentRaiseStatus == undefined) {

                        status = false;

                        console.log('IncidentRaiseStatus is undefined');

                    }

                    if (status == false) {

                        InitOnScreenNotification(validationMsg + '<br> : ' + Tickets, 'validationmsg');

                        console.log('status is false');

                        status = false;

                    }

                }

            }).fail(function (response, err) {

                console.log("fail block");

                console.log(response);

                console.log(err);

                status = false;

            }).always(function () {

                console.log("Completed");

            })

        }

        else {

            console.log('else block variables null');

            InitOnScreenNotification('Please enter required data', 'validationmsg');

            status = false;

        }

    }

    catch (e) {

        status = false;

        console.log("catch block");

        console.log(e.message);

        console.log("error occured isTicketExists()");

    }

    return status;

}


Use Case #3: The 'Service Window' field on the Incident details page should be hidden for the Analysts. The Analysts should not change the Service Window of the Incidents.

Page: Incident > Incident List > Select Incident

JavaScript Logic: Disable (Freeze) the Service Window field if an Analyst has logged in. 

$(document).ready(function () {




        $('#BodyContentPlaceHolder_ddlSLA').prop('disabled', true);




        var UserID = getCallerID();      




        debugger;

        var settings = {

            "async": false,

            "crossDomain": true,

            "url": "http://localhost/SummitWS/REST/Summit_RESTWCF.svc/RESTService/CommonWS_JsonObjCall",

            "method": "POST",

            "headers": {

                "content-type": "application/json"




            },

            "processData": false,

            "data": "{\"ServiceName\":\"ADM_Get_DynamicWebServiceResult\",\"objCommonParameters\":{\"_ProxyDetails\":{\"Password\":\"test@123\",\"UserName\":\"honnambika.m@symphonysummit.com\",\"ProxyID\":0,\"ReturnType\":\"JSON\",\"OrgID\":1},\"ServiceName\":\"IM_CheckAdmin\",\"objDynamicWebService\":{\"InputString\":\"{\\\"UserID\\\":\\\"" + UserID + "\\\"}\"}}}"

        }

        var Isexiststicket = $.ajax(settings).done(function (response) {




            if (response) {

                result = JSON.parse(response);                if (result.OutputObject.SUBROOT != "") {                    if (result.OutputObject.SUBROOT[0].Column1 == 1) {                        $('#BodyContentPlaceHolder_ddlSLA').prop('disabled', false);                    }                }            }        }).fail(function (response, err) {            console.log("fail block");            console.log(response);            console.log(err);            status = false;        }).always(function () {            console.log("Completed");        })    });