I've created a script which would automatically fill in the values in No. Of Packages Column which is a standard column when the program opens:
The expected behaviour is when the user enters the No. package values , hit enter or apply and close the program, then a record is supposed to be created in MMS450 :
The same doesn't happen when the values are filled in via the H5 script. I noticed that few classes (Eg. is-dirty-cell) get added when the user manually types in and tried to simulate the same as well. But that didn't work. Also tried simulating keystrokes via script and setting focus to textbox.
/**
** MMS452 Calculate and fill no of packages segment
**
** Developed By: SuriyaN@fortude.co
** Date: 2023-10-12
**
**/
class MMS452_CalculateNoOfPackages {
private controller: IInstanceController;
private log: IScriptLog;
private args: string;
private miService;
private detachRequesting: Function;
private detachRequested: Function;
constructor(scriptArgs: IScriptArgs) {
this.log = scriptArgs.log;
this.args = scriptArgs.args;
this.controller = scriptArgs.controller;
if (ScriptUtil.version >= 2.0) {
this.miService = MIService;
} else {
this.miService = MIService.Current;
}
}
public static Init(args: IScriptArgs, controller: IInstanceController): void {
new MMS452_CalculateNoOfPackages(args).run(args);
}
private async run(args): Promise<void> {
const list = this.controller.GetGrid();
this.populateData(list);
this.attachEvents(this.controller);
}
private attachEvents(controller: IInstanceController): void {
this.detachRequesting = controller.Requesting.On((e) => {
this.onRequesting(e);
});
this.detachRequested = controller.Requested.On((e) => {
this.onRequested(e);
});
}
private onRequested(args: RequestEventArgs): void {
const list = this.controller.GetGrid();
if (args.commandType === "PAGE" && args.commandValue === "DOWN") {
this.populateData(list);
}else {
this.detachEvents();
}
}
private detachEvents(): void {
this.detachRequesting();
this.detachRequested();
}
private async populateData(list)
{
const dataset: any[] = list.getData();
console.log(list.getData().length)
for (let i = 0; i < list.getData().length; i++) {
const data = dataset[i];
var transQty = list.getData()[i].WSTRQT;
var stdQty = list.getData()[i].WSD1QT;
data["WSNBPA"] =String(Math.ceil(transQty / stdQty));
}
list.setData(dataset);
}
private async onRequesting(args: CancelRequestEventArgs) {
console.log(args);
}
}
Any help is appreciated.