I have a client script which should update a check...
# suitescript
s
I have a client script which should update a checkbox based on a dialog box confirmation. I’m not able to figure out what’s wrong with it. It prints till Record value updated but the record does not get saved.
Copy code
function saveRecord(context) {
            var record = currentRecord.get();

            if (fieldChangeIds.length > 0) {
                try {
                    var options = {
                        title: 'Confirm',
                        message: 'Do you want to send massage of this field change.'
                    };

                    //Send mail if user press ok
                    function success(result) {
                        var currentIds = context.currentRecord.getText({ fieldId: 'custbody_ids_to_send_notification' })
                        log.debug('currentIds: ' + currentIds);
                        for (var i = 0; i < fieldChangeIds.length; i++) {
                            if (currentIds.includes(fieldChangeIds[i])) {
                                var oldfieldValue = getPreviousValue(currentIds, fieldChangeIds[i])
                                var newfieldValue = context.currentRecord.getValue({ fieldId: fieldChangeIds[i] })
                                currentIds.replace(String(oldfieldValue), String(newfieldValue));
                                log.debug('Existing record edited successfully');
                            } else {
                                var newfieldValue = context.currentRecord.getValue({ fieldId: fieldChangeIds[i] })
                                currentIds += '<tr> <td> ' + fieldChangeIds[i] + ' </td> <td> ' + newfieldValue + ' </td>  </tr>'
                                log.debug('Adding new Id ');
                            }
                        }

                        log.debug('Current Ids: ', currentIds)
                        record.setText({ fieldId: 'custbody_ids_to_send_notification', text: currentIds });
                        // context.currentRecord.setValue({ fieldId: 'custbody_send_mail', value: true });
                        record.setValue({ fieldId: 'custbody_send_mail', value: true });
                        log.debug('Record value updated');

                        return true;
                    }

                    function failure(reason) {
                        log.debug('Failure: ' + reason);
                    }
                    
                    return dialog.confirm(options).then(success).catch(failure);
                }
                catch (e) {
                    log.debug('Error : ', e)
                    return false;
                }
            }            
        }
b
your saveRecord entry point does not return true or false
which is the same as retuning false
s
even if i add
return true
after
dialog.confirm
it still wouldn’t work
b
thats not how promises work
s
okay. any suggestions?
b
s
This worked. Thanks a lot.