Hi,
With Suite 8 and Optimus, how to call an event (fire()) in the promise of the send() method ?
The component.events.fire() method seems not to work in the promise !
My snippet :
const send = this.form.send(“http://localhost/duplicRow.php”, “POST”, 1).then(function(json){
var obj = JSON.parse(json);
if (obj.res = “Successful”) { console.log("item successfuly duplicated - newid: "+obj.newid); }
form.events.fire(“insertRow”, [obj.newid]); // only this line is not working
});
Can anyone help me to solve this issue ?
thanks
Hello, first you are trying to fire fire() without referencing ‘this’, but I believe it is probably a matter of context. ‘this’ inside the promise assumes another context and not the component’s. One solution is to store ‘this’ inside another variable before calling send, then inside then() you can use the variable with the upper context.
This way:
const $this = this; // guarding top context
const send = this.form.send(“http://localhost/duplicRow.php”, “POST”, 1).then(function(json){
var obj = JSON.parse(json);
if (obj.res = “Successful”) { console.log("item successfuly duplicated - newid: "+obj.newid); }
$this.form.events.fire(“insertRow”, [obj.newid]); // only this line is not working
});
Hope it helps you.
2 Likes
It works fine, thank you very much
1 Like