Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2019 07:27 AM
Hi, how do I get current.sys_id and parent.sys_id to a Script Include?
My code so far
Business rule:
(function executeRule(current, previous /*null when async*/) {
var checkIpo = new checkVatIpo();
checkIpo.updateVat(current.task); //parent.sys_id
})(current, previous);
Script Include:
updateVat: function(projectSysId) { //parent.sys_id
var costPlan = new GlideRecord('cost_plan');
costPlan.addQuery('task', projectSysId);
costPlan.query();
if (costPlan.next()) {
gs.info('COST ' + this.sysId());
costPlan.setValue('u_eligible_vat', true);
var totalSum = costPlan.getValue('cost_local_currency');
if (projectSysId.getValue('u_vat_proj') == 'twenty_five'){
costPlan.setValue('u_new_vat',(totalSum*0.25));
}
if(projectSysId.getValue('u_vat_proj') == 'nineteen'){
costPlan.setValue('u_new_vat',(totalSum*0.19));
}
if(projectSysId.getValue('u_vat_proj') == 'no_tax'){
costPlan.setValue('u_new_vat','0');
}
var newSum = parseFloat(totalSum) + parseFloat(costPlan.getValue('u_new_vat'));
costPlan.setValue('cost_local_currency', parseFloat(newSum));
costPlan.update();
}
},
Solved! Go to Solution.
1 ACCEPTED SOLUTION

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2019 07:51 AM
try
(function executeRule(current, previous /*null when async*/) {
var checkIpo = new checkVatIpo();
checkIpo.updateVat(current);
})(current, previous);
updateVat: function(projectSysId) {
//projectSysId.sys_id is same as current.sys_id
//projectSysId.task is same as current.task
var costPlan = new GlideRecord('cost_plan');
costPlan.addQuery('task', projectSysId.task);
costPlan.query();
if (costPlan.next()) {
gs.info('COST ' + this.sysId());
costPlan.setValue('u_eligible_vat', true);
var totalSum = costPlan.getValue('cost_local_currency');
if (projectSysId.getValue('u_vat_proj') == 'twenty_five'){
costPlan.setValue('u_new_vat',(totalSum*0.25));
}
if(projectSysId.getValue('u_vat_proj') == 'nineteen'){
costPlan.setValue('u_new_vat',(totalSum*0.19));
}
if(projectSysId.getValue('u_vat_proj') == 'no_tax'){
costPlan.setValue('u_new_vat','0');
}
var newSum = parseFloat(totalSum) + parseFloat(costPlan.getValue('u_new_vat'));
costPlan.setValue('cost_local_currency', parseFloat(newSum));
costPlan.update();
}
},
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2019 07:28 AM
change your method signature and send as parms

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2019 07:45 AM
which table you are running business rule on ?

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-19-2019 07:51 AM
try
(function executeRule(current, previous /*null when async*/) {
var checkIpo = new checkVatIpo();
checkIpo.updateVat(current);
})(current, previous);
updateVat: function(projectSysId) {
//projectSysId.sys_id is same as current.sys_id
//projectSysId.task is same as current.task
var costPlan = new GlideRecord('cost_plan');
costPlan.addQuery('task', projectSysId.task);
costPlan.query();
if (costPlan.next()) {
gs.info('COST ' + this.sysId());
costPlan.setValue('u_eligible_vat', true);
var totalSum = costPlan.getValue('cost_local_currency');
if (projectSysId.getValue('u_vat_proj') == 'twenty_five'){
costPlan.setValue('u_new_vat',(totalSum*0.25));
}
if(projectSysId.getValue('u_vat_proj') == 'nineteen'){
costPlan.setValue('u_new_vat',(totalSum*0.19));
}
if(projectSysId.getValue('u_vat_proj') == 'no_tax'){
costPlan.setValue('u_new_vat','0');
}
var newSum = parseFloat(totalSum) + parseFloat(costPlan.getValue('u_new_vat'));
costPlan.setValue('cost_local_currency', parseFloat(newSum));
costPlan.update();
}
},