This topic contains 4 replies, has 0 voices, and was last updated by j.j 6 years, 11 months ago.

  • Author
    Posts
  • #18239

    NateS

    I created a client script that prompts the user with an alert when a custom field that I created within the sales order is checked/true. Everything is fine if the logic of the script isn’t triggered based on the custom field. But when the custom field is checked the alert displays as expected, but then after editing the sales order and unchecking the box I can’t save the record. I can’t save it even if I reload the page and try again, or even if I deactivate the script and reload the page and try to save it. The only way for me to actually be able to save the sales order after this has happened is for me to go into my browser and clear the cache, then I can save the record again. What I mean by I can’t save the record is that when I click on save nothing happens, it just sits on that page. Below is my script.

    Code:
    /**
    *@NApiVersion 2.0
    *@NScriptType ClientScript
    */

    define([‘N/ui/dialog’],

    function(dialog) {

    function verifyPrice(context) {
    var currentRecord = context.currentRecord;
    // var fieldName = ‘custbody_verify_price’;

    if(currentRecord.getValue(‘custbody_verify_price’) == true){

    var options = {
    title: ‘VERIFICATION NEEDED’,
    message: ‘Prices don’t match’
    };

    try {

    dialog.alert(options);

    log.debug ({
    title: ‘Success’,
    details: currentRecord.getValue(‘transid’)
    });

    } catch (e) {

    log.error ({
    title: e.name,
    details: e.message
    });
    }

    }

    }

    return {
    saveRecord: verifyPrice
    };
    });
    This is a cached copy. Click here to see the original post.

  • #18240

    Vesku1980

    Save function needs return True to be executed.


    NateS replied on 10/05/2017, 11:44 AM: So I can just add an else {return true}?

  • #18241

    pcutler

    Exactly:

    if(currentRecord.getValue(‘custbody_verify_price’) == true){ …} else { return true; }

  • #18242

    pcutler

    Also, you should return false in the case that you do want to prevent the save operation.

  • #18243

    j.j

    on this same topic i am using dialog.confirm(options) – if ok then save the record, issue is dialog.confirm returns a promise object, if i use callback then return true does not work. here is the code :

    function success(result) {

    if (result)

    {alert(“Oked ” + result);

    return true;}

    else

    {alert(“Cancelled ” + result);

    return false;}

    }

    function failure(reason) {

    alert(“Failure: ” + reason);

    return false;

    }

    dialog.confirm(options).then(success).catch(failur e);

You must be logged in to reply to this topic.