What is the best practice to be followed when I would like to add few functions in the OOB Script Include

Raji10
Tera Contributor

Hi All,

I have to add few functions in the OOB Script Include(reusing the other functions in the script include), but stuck with the dilemma between creating (duplicating) a new script include or modify the existing oob one. In the latter case, the challenge is to check the skipped file in every upgrade.

1 ACCEPTED SOLUTION

HI,

Let's say if you have a function in KnowledgeAccessSNC and you want to modify that function then what you should do is copy that function form KnowledgeAccessSNC and add it to KnowledgeAccess script include and modify that function here.

 

So what will happen is if you call the function as new KnowledgeAccess().functionName() then it will not use the function from KnowledgeAccessSNC but from KnowledgeAccess. if the function is not present here then it will use it from KnowledgeAccessSNC.

So basically KnowledgeAccess is used for overriding any function in extended Script include which is readonly or not recommended to modify.

 

Thanks,
Ashutosh Munot

View solution in original post

6 REPLIES 6

Subhajit Majumd
Giga Contributor

Hi Raji

I am not 100% sure but this might help. It's about extension point. Please check the below URL.

 

https://docs.servicenow.com/bundle/newyork-application-development/page/build/applications/concept/e...

 

Thanks

Subhajit Majumder

If this helps, please mark helpful.

Harsh Vardhan
Giga Patron

you can deactivate the ootb one and create new script include and add your new function there. 

kindly have a look on below thread. it has explained very well . 

https://community.servicenow.com/community?id=community_question&sys_id=1698c700db6aa340b1b102d5ca96...

SatheeshKumar
Kilo Sage

Go with modifying the OOB Record!!

ServiceNow’s changed their best practice recommendation several times over the years.  Their current suggestion is to not copy records, but instead modify when we have to change something in OOTB.

find_real_file.png

 

Community Alums
Not applicable

Hi Raji,

You can extend the OOTB object (script include) and include the new functions there. 

Take this as an example.

Custom functions: Hello.js

var Hello = Class.create();
Hello.prototype = Object.extendsObject(HelloBase, {
 
/* insert your functions here */

    type: 'Hello'
});


OOTB functions: HelloBase.js

var HelloBase = Class.create();
HelloBase.prototype = {
	initialize: function(){},
	
/* out the box functions */
    type: 'HelloBase'
};