Hi All, is anybody knows if it possible to use dia...
# suitescript
s
Hi All, is anybody knows if it possible to use dialog.confirm (from 'N/ui/dialog' module) in saveRecord (clientscript) function? I`m using for a now JS build in 'confirm' function in order to get user response for particular situation. From what I found the design of confirm box cannot be changed (number of buttons, name for buttons etc....). I found module in suitescript that provides more flexible confirm box, but the problem is it return promise object (instead boaleen in standard JS confirm function) and not stop the code running. My code is something like this: define(['N/ui/dialog'], function (dialog) { /** *@NApiVersion 2.1 *@NScriptType ClientScript */ function saveRecord(context) {debugger options = {title: 'I am an Alert',message: 'Click OK to continue.'}; function success(result) {return true}; function failure(reason) {return false}; var k=dialog.confirm(options).then(success).catch(failure) return k } The big problem is message box appears only after save function is already executed, what makes it useless. The code doesn`t wain for user response.
c
What are you getting them to confirm? Can you move that confirmation to a field edit or similar instead?
s
I have 2 custom fields in transaction form which represent billing periods of the bill (one for start period and second for end period). Both fields are dates type. After user clicks 'Save' button, the script compare if selected posting period is within billing periods. If yes, continue to save. If no, pop up alert which have 3 options: • Save transaction as is • Automatically Change posting period to correct one • Cancel saving I don`t think that confirmation as field edit is good idea because it need to be run on 3 fields....
a
I don't think you're understanding promise callback functions correctly. the cancel/ return false scenario is NOT a failure
I think your success function needs to return result, rather than true. the value will be true/false depending if ok or cancel was clicked you're effectively returning true if... any button is clicked.
it could ALSO be that the returned promise even without it being resolved actually passes as truthy test and saves the record... in that case... you'd have to force it resolve somehow... its Sunday, I'm not working on that 😄
s
That`s my biggest problem, its shows the dialog box after the transaction is already saved (I don`t why its works like this with promises objects in saveRecord function). I will try my luck tomorrow....
r
You can return false if the condition doesn't satisfy it will not allow to save until end user meets condition .
b
saveRecord is a synchronous entry point, you must return true or false to determine if the save fails
dialog.confirm is asynchronous, it resolves to true or false later, which is too late for saveRecord purposes
there are desperation attempts like making your saveRecord return false to make the save fail and then do the equivalent of clicking the save button again in code, but thats a lot of work to try and not use window.confirm
s
Great. Than you very much for explanation and saving my time from desperate searches for unexcited solutions.
a
@Slava For nice blocking dialogs or progress or what not I ditch the dialog module more often than not I end using SweetAlert(third party JS library) this worked for me for more than 6 years and I never found an issues with NetSuite.
To be clear I not fan of third party libraries with NetSuite at all, the only libraries I ever used without any issues for 5+ years are: • moment (Dates). • papaparse (CSVs). • sweetalert and sweetalert2. • datatables.
s
@alien4u I heard about SA, but I`m afraid to use it with NetSuite as there is always a risk that something gonna be break in the middle and you don`t want to stuck the application because of design. But probably if it works for you for 5+ years, it is worth to integrate it. Thank you.