7px
08/02/2022, 7:13 AMafterSubmit()
, to load a record and get values, then finally send those values back to the Client Script before returning true and committing the save.
I've successfully passed values from the CS to the SL, but I'm at a loss at returning the value back to the CS without the page just loading into a new page and losing all the input in the form.
The intended result would be that after clicking Save on the form, the Suitelet is fired, a record is loaded and its values are retrieved and sent back to the Client Script, and it applies the values on the form before returning true for afterSubmit()
to finish.
Any and all input appreciated.NElliott
08/02/2022, 9:32 AM7px
08/03/2022, 12:44 AMafterSubmit()
, ideally the Suitelet will load and run in the background without unloading the form and losing all the user input.
I've already managed to pass values from the Client Script to the Suitelet, but I'm having difficulty returning the values the latter generates to the former.
I saw a thread mentioning this was possible in Suitescript 1, so I'm trying to figure out if it's feasible in Suitescript 2.x or not.battk
08/03/2022, 2:22 AMbattk
08/03/2022, 2:22 AMmichoel
08/03/2022, 2:22 AM7px
08/03/2022, 8:08 AMfunction onSaveRecord() {
let _IF_record = currentRecord.get();
let _IF_uuid = _dr_record.getValue({
fieldId:"custbody_if_uuid"
});
let _salesorder_reference = _IF_record.getValue({ fieldId:"createdfrom" });
function AppendSalesOrderField(idk) {
//spits out a string: the url of a suitescript
var suiteletUrl = url.resolveScript({
scriptId: 'customscript460',
deploymentId: 'customdeploy1',
returnExternalUrl: false,
params: {
tranid: _salesorder_reference,
uuid: _IF_uuid
}
});
https.get.promise({
url: suiteletUrl
}).then(function(response){
window.onbeforeunload = null;
location.href = suiteletUrl;
SucceededAppending(response)
}).catch(function(reason){
log.error("F", reason);
FailedAppending(reason)
});
}
function SucceededAppending(wat) {
alert("worked: " + wat);
return false;
}
function FailedAppending(huh) {
alert("failed: " + huh);
}
try {
AppendSalesOrderField();
} catch (e) {
FailedAppending(e);
}
}
exports.saveRecord = onSaveRecord;
return exports;
});
Suitelet
function onRequest(context) {
if (context.request.method === 'GET') {
let _id = parseInt(context.request.parameters.tranid, 10);
let _uu = context.request.parameters.uuid;
context.response.write("uuid: " + _uu + "\ntranid " + _id);
} else {
context.response.write("<script>window.close();</script>");
}
}
exports.onRequest = onRequest;
return exports;
I'm currently stumped at the suitelet here, as I'm unaware of any method of loading the suitelet without closing out the current page to render the result.michoel
08/03/2022, 8:52 AM7px
08/04/2022, 1:18 AMcontext.response
object, unless there's a limitation I'm unaware of?michoel
08/04/2022, 1:26 AMcontext.response.write
) should be available in the client script in the response
object7px
08/04/2022, 4:07 AMObject.keys()
on the response object doesn't seem to return the values I'm writing from the suitelet neither.
Am I supposed to encode the return value? The SL seems to be returning something because it's triggering the correct function on the CS.battk
08/04/2022, 10:01 AMbattk
08/04/2022, 10:02 AMbattk
08/04/2022, 10:04 AM7px
08/05/2022, 4:42 AM<http://https.post|https.post>()
instead of https.get()
. For this very specific use-case, I feel that to be more than enough to get the job done. Thanks again!