- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2021 06:55 AM
Hi Team,
I am working on a requirement.
Scenario:
I want to create a record with some default values in a custom table if any records get created in the incident, request, or change table.
I am trying to achieve this through Script Include and Business rule mentioned below. Please let me know what is wrong in that?
Script Include:
var CallApproval = Class.create();
CallApproval.prototype = {
initialize: function() {
},
insertapprovalrecord: function(){
var gr = new GlideRecord('x_intp_custom_appr_custom_approval');
gr.initialize();
gr.approver = this.requested_for.manager;
gr.state = 'Requested';
gr.source_table_new = this.sys_id;
gr.source_table = reqtab.sys_id;
gr.insert();
},
type: 'CallApproval'
};
Business Rule:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var callapproval = new CallApproval().insertapprovalrecord(current);
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-20-2021 07:40 AM
Hi Nick,
You can leave your business rule as is, it's fine to pass current into the script include function call as it's linked by reference.
Another point is that you should really return a value from the function in your script include, as your BR is expecting it as you're storing the result in a variable. Just replace this, gr.insert(); with return gr.insert();
This with then return the sys_id of your created record to your callapproval variable in your BR.
Thanks
Justin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-23-2023 12:29 AM
Hi nickanice,
Its an old question but i here's my observations:
Two things I've noticed:
1. You're not using passing 'current' option in Script include
2. Unknown variable object: 'reqtab'.