How do I get current.sys_id and parent.sys_id to a Script Include?

Jonatan4
Giga Guru

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();
		}
	},
1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

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();
	}
},

View solution in original post

3 REPLIES 3

ggg
Giga Guru

change your method signature and send as parms

Mike Patel
Tera Sage

which table you are running business rule on ?

Mike Patel
Tera Sage

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();
	}
},