How to create records in a table using script include and business rule

nickanice
Tera Contributor

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);

 

 

 

1 ACCEPTED SOLUTION

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

 

 

View solution in original post

5 REPLIES 5

Pankaj Singh1
Tera Contributor

 

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'.