Hi,
I have an issue where there are three api calls in an Enter event but all three are failing.
Tried to use async and await functionality to see if atleast the first api works but that also failed.
I don't know what is missing. Normally in other H5 scripts development I have used "Enter" event a lot and working but don't know what is missing here.
Below is the typescript logic for Enter event, Run method and one of the api call I am doing.
Can you let me know what is missing?
private run(controller): void {
var userContext = ScriptUtil.GetUserContext("USID");
this.userId = userContext;
console.log("user" , this.userId);
console.log("InRun");
this.contentElement = this.controller.GetContentElement();
this.F3 = SessionCache.Get("Flag3|");
//if (this.F3 === true) {
// this.HCAT = SessionCache.Get("HoldCat|");
// SessionCache.Remove("Flag3|");
//SessionCache.Remove("HoldCat|");
//}
this.addLabel();
let HoldCategory = this.executeByTransaction();
//this.addCheckbox();
//this.addButton();
/* this.unsubscribeRequesting = this.controller.Requesting.On((e) => {
if (e.commandType === "KEY" && e.commandValue === "ENTER") {
console.log("InEnter");
let panelName = this.controller.GetPanelName();
switch (panelName) {
case "MMA130E0":
if (!this.ValidateStatus()) { e.cancel = true; }
if (!this.ValidateTT()) { e.cancel = true; }
//if (SessionCache.Get("HoldCAT|") === true)
this.addHoldCategory();
//if (SessionCache.Get("HoldRSN|") === true)
this.addHoldReason();
return;
//setTimeout(() => { this.controller.PressKey("Enter"); }, 400);
//setTimeout(() => {this.addTaggingType();}, 8000);
this.addTaggingType()
this.updateInfo();
// SessionCache.Remove("Flag3|");
//SessionCache.Remove("HoldCat|");
return this;
}
}
});
this.unsubscribeRequested = this.controller.Requested.On((e) => {
// this.onRequestCompleted(e);
if (e.commandType === "KEY" && e.commandValue === "ENTER") {
// SessionCache.Remove("Flag3|");
//SessionCache.Remove("HoldCat|");
}
}); */
this.attachEvents(this.controller);
}
private attachEvents(controller: IInstanceController){
this.unsubscribeRequesting = controller.Requesting.On((e:CancelRequestEventArgs)=>{
console.log("e.Comm" , e.commandValue); //
console.log("e.Commtype" , e.commandType);
if (e.commandType === "KEY" && e.commandValue === "ENTER") {
console.log("InEnter");
let panelName = this.controller.GetPanelName();
switch (panelName) {
case "MMA130E0":
if (!this.ValidateStatus()) { e.cancel = true; }
if (!this.ValidateTT()) { e.cancel = true; }
this.ITNO = ScriptUtil.GetFieldValue("WWNITN");
if (this.ITNO === "") {
this.ITNO = ScriptUtil.GetFieldValue("WWITNO");
}
this.BANO = ScriptUtil.GetFieldValue("WWNBAN");
if (this.BANO === "") {
this.BANO = ScriptUtil.GetFieldValue("WWBANO");
}
this.HCAT = SessionCache.Get("HoldCat|");
this.HCAT = this.HCAT.trim();
if (this.HCAT === "") this.HCAT = " ";
if(this.ITNO != ""){
this.callAPI();
e.cancel = false;
}
//return;
//if (SessionCache.Get("HoldRSN|") === true)
// this.addHoldReason();
//setTimeout(() => { this.controller.PressKey("Enter"); }, 400);
//setTimeout(() => {this.addTaggingType();}, 8000);
this.updateInfo();
this.addTaggingType()
//this.updateInfo();
return this;
}
}
this.detachEventsRequesting();
});
}
private detachEventsRequesting(){
this.unsubscribeRequesting();
}
private async callAPI(){
let getData = await this.addHoldCategory(this.ITNO, this.BANO, this.HCAT);
if (getData != null) {
console.log("getdata" + getData);
}
}
private addHoldCategory(ITNO, BANO, HCAT) {
//if (this.HRSN === "") this.HRSN = " ";
console.log("Inaddholdcat", this.ITNO,ITNO);
console.log("Inaddholdcat1", this.BANO, BANO);
console.log("Inaddholdcat2", this.HCAT, HCAT);
console.log("CUSEXTMI");
var _this = this;
return new Promise<any>((resolve) => {
let record = {
'FILE': "MILOMA",
'PK01': ITNO,
'PK02': BANO,
'A030': HCAT };
//const outputFields = ["A030"];
MIService.Current.execute("CUSEXTMI", "AddFieldValue", record).then((response: IMIResponse) => {
console.log("responseaddholdcategory" , response);
if (null != response) {
resolve(response);
}
else {
resolve(null);
}
}).catch(function (response) {
console.error(response.errorMessage);
});
});