- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2025 12:15 AM
Dear,
I've written a script include and I wanted to call a function from that creates a record in another application from ServiceNow.
I've configured the business rule as,
Can you please tell what is the mistake here.
Regards,
Prashanthi Sathri
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 06:09 AM
@PRASHANTHI SATH , You can execute the script include in the following manner,
If your script include looks like the one given below:
var TestDemoFunc = Class.create();
TestDemoFunc.prototype = {
initialize: function() {
},
returnSomething:function(sysId){
gs.info('Inside Script Include');
//process some logic using sysID
return 'Hello';
},
executeSomething:function(){
gs.info('Execute Something');
},
type: 'TestDemoFunc'
};
Then go the Business rule and click on Advanced tab, from there you can invoke the script include as shown below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//Exeute the script include and store the result
var storedValue = new global.TestDemoFunc().returnSomething(current.sys_id);
gs.info('Stored Value is:'+storedValue);
//Just execute the script include
new global.TestDemoFunc().executeSomething();
})(current, previous);
You can take the help of the current object and pass it to your function in the script include. Attaching the screenshots for your reference.
Kindly mark my response as helpful if it helped you and let me know if you have any questions further.
Thanks,
Mahesh.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 05:42 AM
Hi @PRASHANTHI SATH ,
I have created a comprehensive lesson on Business Rules and Script Includes, designed to help you gain a deeper understanding of how to use them effectively. This lesson will enhance your ability to write high-quality, maintainable scripts by applying best practices in code quality and optimization.
Hope this helps.
Complete Training Course on ServiceNow Business Rules for Developers, Admins and IT Professionals
Mastering GlideAjax and Script Includes: A Guide for ServiceNow Developers
Leveraging Software Design Patterns with extendObject() in ServiceNow Script Include for Developers
Master Good Software Architecture with Object.extendsObject() | A Guide for ServiceNow Developers
Object-Oriented Principles in ServiceNow | A Guide for Architects & Developers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2025 06:09 AM
@PRASHANTHI SATH , You can execute the script include in the following manner,
If your script include looks like the one given below:
var TestDemoFunc = Class.create();
TestDemoFunc.prototype = {
initialize: function() {
},
returnSomething:function(sysId){
gs.info('Inside Script Include');
//process some logic using sysID
return 'Hello';
},
executeSomething:function(){
gs.info('Execute Something');
},
type: 'TestDemoFunc'
};
Then go the Business rule and click on Advanced tab, from there you can invoke the script include as shown below:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
//Exeute the script include and store the result
var storedValue = new global.TestDemoFunc().returnSomething(current.sys_id);
gs.info('Stored Value is:'+storedValue);
//Just execute the script include
new global.TestDemoFunc().executeSomething();
})(current, previous);
You can take the help of the current object and pass it to your function in the script include. Attaching the screenshots for your reference.
Kindly mark my response as helpful if it helped you and let me know if you have any questions further.
Thanks,
Mahesh.