I have created a script which should stop creating order line in OIS101/H panel for certain item number. If criteria does not match then order line should be created.
I have used onRequesting to capture ENTER key events, args.cancel = true and controller.PressKey("ENTER")
To stop order line - The script is working fine by using args.cancel = true and not proceeding the line creation
To create order line - If I use Enter key from keyboard, it is not proceeding to next panel. But when using Next button in OIS101/H panel it is working fine and moving to next panel.
Below is the script, please look at it and let me know how to proceed with next panel after using args.cancel.
var OIS101_checkLine = new function() {
var _this = this;
this.Init = function (scriptArgs) {
this.controller = scriptArgs.controller;
this.log = scriptArgs.log;
this.args = scriptArgs.args;
this.ORNO = this.controller.GetValue("OAORNO");
console.log("ORNO: " + this.ORNO);
this.CUNO = this.controller.GetValue("OACUNO");
console.log("CUNO: " + this.CUNO);
this.validation = true;
if (ScriptUtil.version >= 2.0) {
this.miService = MIService;
} else {
this.miService = MIService.Current;
}
this.unsubscribeRequesting = this.controller.Requesting.On(function (e) {
_this.onRequesting(e);
});
this.unsubscribeRequested = this.controller.Requested.On(function (e) {
_this.onRequested(e);
});
};
this.onRequesting= function(e){
var _this = this;
_this.WHLO = _this.controller.GetValue("WBWHLO");
console.log("WHLO: " + _this.WHLO);
if (e.commandType === "KEY" && e.commandValue === "ENTER") {
if(_this.validation == true) {
e.cancel = true;
_this.checkline(e.commandValue);
}
}
}
this.checkline = function(commandValue) {
var _this = this;
var j= 0;
_this.list = _this.controller.GetGrid();
var dataset = _this.list.getData();
for (var i = 0; i < dataset.length; i++) {
_this.ITNO = dataset[i]['W2ITNO'];
console.log("ITNO Value----"+_this.ITNO+ "-----"+i);
_this.ORQA = dataset[i]['W2ORQA'];
console.log("quantity Value----"+_this.ORQA+ "-----"+i);
if (_this.ITNO != "" && _this.ITNO != null && _this.ITNO != "undefined") {
if(_this.ORQA != "" && _this.ORQA != null && _this.ORQA != "undefined") {
var myRequest = new MIRequest();
myRequest.program = "CMS474MI";
myRequest.transaction = "GetUdefContent";
myRequest.record = {UDFT: 1, ITNO: _this.ITNO, CFMG: "MOC", CFMF: "MOC"};
_this.miService.executeRequest(myRequest).then(function (response) {
_this.CFMA = response.item.CFMA;
if(_this.CFMA == "YES" && _this.WHLO != "61X" && _this.WHLO != "35X" && _this.WHLO != "27E"){
console.log("Do not create Line");
j++;
}
console.log(_this.CFMG+" "+ _this.CFMA+" "+ _this.ITNO+" "+ _this.ORQA)
}).catch(function (response) {
});
}
}
}
setTimeout(function () {
if(j>0){
console.log("Do not create Line BLOCK IT");
} else {
_this.validation = false;
_this.controller.PressKey("ENTER");
}
}, 2000);
}
this.onRequested = function (e) {
this.unsubscribeRequested();
this.unsubscribeRequesting();
};
return OIS101_checkLine;
}();