Methods use in Callout
Making Callout Active/InActiveĀ
On calling any calloutprototype method you can set that callout to active so that if callout is already active then will not call again. See below code exampleĀ
//if callout is active and receiving value parameter to callout is not valid then returnĀ
if (this.isCalloutActive() || value == null || value.toString() == "") {Ā
return"";Ā
}Ā
//make callout activeĀ
this.setCalloutActive(true);Ā
Ā
In the end of the callout prototype method after successfully execute your logic, make this callout inactive by below methodĀ
this.setCalloutActive(false);Ā
Ā
Get/Set Value in CalloutĀ
You can get the current active tab fields value with method mTab.gelValue(āColumnNameā)Ā
Ā
var netsalary,gross, basic, hra;Ā
// get valuesĀ
basic = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_BasicSalary"));Ā
hra = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_HRA"));Ā
Following example demonstrates how you can set the values of the fields in the current active tab with method mTab.setValue(āColumnNameā,value);Ā
Ā
mTab.setValue("VAT_NET", netsalary);Ā
mTab.setValue("VAT_Gross", gross);Ā
You can explore more example of callouts in following folder.Ā
āVIS/Scripts/Model/callouts.jsā, callout run at client sideĀ Ā
Ā
Full Example of Callout as below (the sample code you can find from Demo Partner Kit)Ā
//initialize your module prefix codeĀ
//Here MPC is VATĀ
; VAT = window.VAT || {};Ā
Ā
; (function (VAT, $) {Ā
Ā
/**Ā
Callout ClassĀ
must call this functionĀ
VIS.CalloutEngine.call(this, [className]);Ā
*/Ā
function CalloutEmployeeSalary() {Ā
VIS.CalloutEngine.call(this, "VAT.CalloutEmployeeSalary"); //must callĀ
};Ā
Ā
/**Ā
*Inherit CallourEngile ClassĀ Ā
*/Ā
VIS.Utility.inheritPrototype(CalloutEmployeeSalary, VIS.CalloutEngine);//inherit CalloutEngineĀ
Ā
Ā
//Callout Method defined as Function prototypeĀ
CalloutEmployeeSalary.prototype.netSalary = function (ctx, windowNo, mTab, mField, value, oldValue) {Ā
if (this.isCalloutActive() || value == null || value.toString() == "") {Ā
return"";Ā
}Ā
Ā
this.setCalloutActive(true);Ā
Ā
try {Ā
Ā
var netsalary, gross, basic, hra, pf, tds;Ā
// get valuesĀ
basic = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_BasicSalary"));Ā
hra = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_HRA"));Ā
tds = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_TDS"));Ā
pf = VIS.Utility.Util.getValueOfDecimal(mTab.getValue("VAT_PF"));Ā
Ā
this.log.fine("BasicSalary=" + basic + ", hra=" + hra + ", pf=" + pf);Ā
Ā
netsalary = basic + hra - (pf + tds);Ā
//Gross Salary include allĀ
gross = basic + hra + pf + tds;Ā
Ā
// var isSOTrx = (ctx.getWindowContext(windowNo, "IsSOTrx", true) == "Y");Ā
Ā
mTab.setValue("VAT_NET", netsalary);Ā
mTab.setValue("VAT_Gross", gross);
Ā
}Ā
catch (err) {Ā
VIS.ADialog.info("error in NetSalary" + err, null, "", "");Ā
this.setCalloutActive(false);Ā
return err;Ā
}Ā
this.setCalloutActive(false);Ā
ctx = windowNo = mTab = mField = value = oldValue = null;Ā
return"";Ā
};Ā
Ā
//initialise model object in VATĀ
VAT.Model = VAT.Model || {};Ā
VAT.Model.CalloutEmployeeSalary = CalloutEmployeeSalary; //assign object in Model NameSpaceĀ
Ā
/*********************** Second Callout Class CalloutDepartment*******************/Ā
/**Ā
*Callout Class CalloutDepartmentĀ
*must call this functionĀ
*VIS.CalloutEngine.call(this, [className]);Ā
*/Ā
function CalloutDepartment() {Ā
VIS.CalloutEngine.call(this, "VAT.CalloutDepartment"); //must callĀ
};Ā
/**Ā
*Inherit CallourEngile ClassĀ Ā
*/Ā
VIS.Utility.inheritPrototype(CalloutDepartment, VIS.CalloutEngine);//inherit CalloutEngineĀ
//Callout Method defined as Function prototypeĀ
CalloutDepartment.prototype.showDepartmentCode = function (ctx, windowNo, mTab, mField, value, oldValue) {Ā
if (this.isCalloutActive() || value == null || value.toString() == "") {Ā
return"";Ā
}Ā
Ā
this.setCalloutActive(true);Ā
Ā
try {Ā
var departmentid=value;Ā
$.ajax({Ā
url: VIS.Application.contextUrl + "VAT/Callout/GetDepartmentCode",Ā
data: { depID: departmentid },Ā
success: function (result) {Ā
if (result) {Ā
mTab.setValue("VAT_DepartmentCode", result);Ā
}Ā
self.setCalloutActive(false);Ā
ctx = windowNo = mTab = mField = value = oldValue = null;Ā
},Ā
error: function (eror) {Ā
self.setCalloutActive(false);Ā
console.log(eror);Ā
self.log.severe(eror.toString());Ā
ctx = windowNo = mTab = mField = value = oldValue = null;Ā
Ā
}Ā
Ā
});Ā
} // re-read customer rulesĀ
catch(err)Ā
{Ā
this.setCalloutActive(false);Ā
this.log.severe(err.toString());Ā
}Ā
Ā
this.setCalloutActive(false);Ā
ctx = windowNo = mTab = mField = value = oldValue = null;Ā
return"";Ā
};Ā
Ā
//initialise model object in VATĀ
VAT.Model = VAT.Model || {};Ā
VAT.Model.CalloutDepartment = CalloutDepartment; //assign object in Model NameSpaceĀ
Ā
})(VAT, jQuery);Ā
Ā
In the above example there are two callout classes and both have one callout methods.Ā Ā
In the first callout method we calculate the Gross Amount of employee and then set gross amount to Gross Field.Ā
In the second callout method we execute database query and set Department code on Employee window corresponding to selected department.Ā
Ā