How to call & extend script include in servicenow

Rajababu
Giga Guru

Hi ,

I want to extend one out of box script include "CSEMailUtil" it's out of box and I created my script include which extend OOB script include below sample code :

Client callable : True

var Getfunction = Class.create();

Getfunction .prototype = Object.extendsObject(CSEMailUtil, {


getValue: function(email) {
var value1 = '';
if (gs.nil(email))
return skills;
var emails = email.split(',');
emails = emails.reduce(function(filtered, mailId) {
if (mailId && !gs.nil(mailId.trim()))
filtered.push(mailId.trim());
return filtered;
}, []);

if (!emails || emails.length <= 0)
return value1;
var gr = new GlideRecord('sn_customerservice_channel_config');
gr.addQuery('email_address', emails);
gr.setLimit(1);
gr.query();
if (gr.next())
skills = gr.u_abc + '';
return value1;
},


type: 'Getfunction'
});

 

In email inbound :

 ((new CSEMailUtil).checkCaseChannel(email.to)) && ((new CSEMailUtil).isUserExist(email.from)) ---> do i  need to make changes into it ?

If yes then what ?

1 ACCEPTED SOLUTION

In email inbound I need to provide the as mentioned the get the content .

So in email inbound : It will be as it is where it will verify channel configuration email associated with with Valuefunction(field on the channel) .

Script include(extend into another script include) it provide accessibility to parent script include function :

"Getfunction .prototype = Object.extendsObject(CSEMailUtil, {"

Email inbound action (body):

current.valuefunction = new Getfunction().getValue(email.to);

GetFunction : Script include which extended to CSEMailUtil or another word which provided access to parent script include function .

getValue : Function defined into extend script include .

It working as desired .

View solution in original post

15 REPLIES 15

I don't agree with your suggestion to update the OOB Script Include it leaves the environment in a skipped upgrade state. If SN refactors it, adds important methods, etc, the customer will miss them.
Instead, extending the SI is best practice, and it's not "copying an object" the way the customization doc from SN is talking about.

Hi,

even ServiceNow recommends updating OOB object and avoid copying objects for minor changes

What are the best practices for customization?

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Rajababu
Giga Guru

I found I did the correct way , Just I missed the to update into the email inbound action .

I extended the script include correctly which provided the excess CSEMailUtil().

 

Hi,

Glad that you got the approach.

But I would suggest to update OOB object as it is recommended by ServiceNow for small changes.

I already shared link above. Please check that

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I saw and totally agree with you, I did in past as well .It's really minor one where only need to add on function into the list which I already did and was working perfectly. Last 1 week I was trying convinced them but they don't agree.

But you know some time you ca'nt do, what do you want ...hehehehehe .

I hope you know, boss/Client is always(if they desperately want) right 🙂