Convert a BR to a Script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 12:10 PM
I'm not sure how to the this completed.
Currently i have a BR to calculate Risk and Impact on a Change Request.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var nRisk = '';
var nImpact = '';
var currType = current.type;
var expC = parseInt(current.getValue('u_risk_question_5'));
var bckP = parseInt(current.getValue('u_risk_question_4'));
var busI = parseInt(current.getValue('u_risk_question_3'));
var comP = parseInt(current.getValue('u_risk_question_2'));
var outS = parseInt(current.getValue('u_risk_question_1'));
var rTTL = expC+bckP+busI+comP+outS;
var impTTL = outS+busI;
if (rTTL > 0 && rTTL < 11) {
current.setValue('risk', 4);
nRisk = 4;
} else if (rTTL > 10 && rTTL < 21) {
current.setValue('risk', 3);
nRisk = 3;
} else if (rTTL > 20 && rTTL < 41) {
current.setValue('risk', 2);
nRisk = 2;
}
else if (rTTL > 40) {
current.setValue('risk', 1);
nRisk = 1;
}
//gs.info("the impact is "+impTTL);
if(impTTL<=1){
current.setValue('impact',4);
nImpact = 4;
}
else if(impTTL>1 && impTTL<=6){
current.setValue('impact',3);
nImpact = 3;
}
else if(impTTL<6 && impTTL>=10){
current.setValue('impact',2);
nImpact = 2;
}
else if(impTTL>10){
current.setValue('impact',1);
nImpact = 1;
}
if((nImpact<3 || nRisk<4) && currType=="standard"){
var msg = "The change type has been switched to 'Normal' due to the risk and impact rating. Standard changes are meant for low risk/low impact recurring changes. You will need to resubmit the Standard Change with a low risk assessment.";
gs.addInfoMessage("Attention: "+msg);
current.setValue('type','normal');
}
})(current, previous);
I'm getting an error
Could not save record because of a compile error: SyntaxError: Expected ',', got 'answer' at line 7, column 1
Script Include
var setChangeRisk = Class.create();
setChangeRisk.prototype = Object.extendsObject(AbstractAjaxProcessor, {
setChangeRisk : function() {
// Add your code here
var nRisk = '';
var nImpact = '';
var currType = current.type;
var expC = parseInt(current.getValue('u_risk_question_5'));
var bckP = parseInt(current.getValue('u_risk_question_4'));
var busI = parseInt(current.getValue('u_risk_question_3'));
var comP = parseInt(current.getValue('u_risk_question_2'));
var outS = parseInt(current.getValue('u_risk_question_1'));
var rTTL = expC+bckP+busI+comP+outS;
var impTTL = outS+busI;
if (rTTL > 0 && rTTL < 11) {
current.setValue('risk', 4);
nRisk = 4;
} else if (rTTL > 10 && rTTL < 21) {
current.setValue('risk', 3);
nRisk = 3;
} else if (rTTL > 20 && rTTL < 41) {
current.setValue('risk', 2);
nRisk = 2;
}
else if (rTTL > 40) {
current.setValue('risk', 1);
nRisk = 1;
}
//gs.info("the impact is "+impTTL);
if(impTTL<=1){
current.setValue('impact',4);
nImpact = 4;
}
else if(impTTL>1 && impTTL<=6){
current.setValue('impact',3);
nImpact = 3;
}
else if(impTTL<6 && impTTL>=10){
current.setValue('impact',2);
nImpact = 2;
}
else if(impTTL>10){
current.setValue('impact',1);
nImpact = 1;
}
///current.update();
if((nImpact<3 || nRisk<4) && currType=="standard"){
var msg = "The change type has been switched to 'Normal' due to the risk and impact rating. Standard changes are meant for low risk/low impact recurring changes. You will need to resubmit the Standard Change with a low risk assessment.";
gs.addInfoMessage("Attention: "+msg);
current.setValue('type','normal');
}
}
answer = ;
type: 'setChangeRisk'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 12:47 PM - edited 02-03-2025 05:36 PM
Seems there are several problems with the above. Extending 'AbstractAjaxProcessor', not declaring 'answer'. Seems you may want to return an object containing nRisk and nImpact. 'current' won't be available unless passed in to the 'setChangeRisk' function.
I suggest that you look at existing script includes in your instance.
If you post your goal, how you intend to use that script include, I believe you will get additional assistance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 07:37 AM - edited 02-04-2025 05:51 PM
@EricG2 ,
I tested using your BR logic in a script include, and created a new BR to call that on the change_request table. See below
The script:
var setChangeRisk = Class.create();
setChangeRisk.prototype = {
initialize: function() {
},
setChgRisk : function(current) {
// Add your code here
var nRisk = '';
var nImpact = '';
var currType = current.type;
gs.log('setChgRisk: currType = ' + currType + ', number = ' + current.number);
// var expC = parseInt(current.getValue('u_risk_question_5'));
// var bckP = parseInt(current.getValue('u_risk_question_4'));
// var busI = parseInt(current.getValue('u_risk_question_3'));
// var comP = parseInt(current.getValue('u_risk_question_2'));
// var outS = parseInt(current.getValue('u_risk_question_1'));
// for testing
var expC = 5;
var bckP = 4;
var busI = 3;
var comP = 2;
var outS = 1;
var rTTL = expC+bckP+busI+comP+outS;
var impTTL = outS+busI;
gs.info("setChgRisk: the rTTL is "+rTTL);
if (rTTL > 0 && rTTL < 11) {
current.setValue('risk', 4);
nRisk = 4;
} else if (rTTL > 10 && rTTL < 21) {
current.setValue('risk', 3);
nRisk = 3;
} else if (rTTL > 20 && rTTL < 41) {
current.setValue('risk', 2);
nRisk = 2;
}
else if (rTTL > 40) {
current.setValue('risk', 1);
nRisk = 1;
}
gs.info("setChgRisk: the impact is "+impTTL);
if(impTTL<=1){
current.setValue('impact',4);
nImpact = 4;
}
else if(impTTL>1 && impTTL<=6){
current.setValue('impact',3);
nImpact = 3;
}
else if(impTTL<6 && impTTL>=10){
current.setValue('impact',2);
nImpact = 2;
}
else if(impTTL>10){
current.setValue('impact',1);
nImpact = 1;
}
///current.update();
if((nImpact<3 || nRisk<4) && currType=="standard"){
var msg = "The change type has been switched to 'Normal' due to the risk and impact rating. Standard changes are meant for low risk/low impact recurring changes. You will need to resubmit the Standard Change with a low risk assessment.";
gs.addInfoMessage("Attention: "+msg);
current.setValue('type','normal');
}
},
type: 'setChangeRisk'
};
The new BR (runs on Insert, Update, and When is 'Before' code:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var newRisk = new setChangeRisk();
newRisk.setChgRisk(current);
})(current, previous);
Result when updating a CHG
If you plan to call the script include from a client script or some other client-side means, then changed are needed to use GlideAjax.
Good luck, post back here and myself or others here can assist you.