override a method in script include

ammar_k
Tera Contributor

Hello, 

i have a ui action that calls this method :

 

new sn_cs_sm.ServiceManagementProblemUtils().createProblemFromCase(current, action);

 

how to override this function 

 

thank you

 

1 REPLY 1

Sanjay191
Tera Sage

Hello @ammar_k 
Please refer below logic and if any help needed please ping me.

To override the createProblemFromCase method in the ServiceManagementProblemUtils script include, you can extend the script include and define your custom logic. Below is an example:

  1. Create a new Script Include that extends ServiceManagementProblemUtils.
  2. Override the createProblemFromCase method with your custom logic.

    var CustomServiceManagementProblemUtils = Class.create();
    CustomServiceManagementProblemUtils.prototype = Object.extendsObject(sn_cs_sm.ServiceManagementProblemUtils, {

    createProblemFromCase: function(current, action) {
    // Custom logic goes here
    gs.info("Custom createProblemFromCase method called.");

    // Example of calling the original method if needed
    var result = this._super(current, action);

    // Add custom logic after calling the original method
    gs.info("Additional custom processing can be done here.");

    return result; // Return the result if needed
    },

    type: 'CustomServiceManagementProblemUtils'
    });

    Explanation:

    • The script include CustomServiceManagementProblemUtils extends the original ServiceManagementProblemUtils.
    • The createProblemFromCase method is overridden to include custom logic.
    • Use this._super(current, action); to call the original method if you want to retain the existing functionality while adding your custom code.


      If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
      Thank You