This topic contains 3 replies, has 0 voices, and was last updated by Mikemacx 7 years, 1 month ago.

  • Author
    Posts
  • #21454

    Mikemacx

    Just a simple question because I'm still getting my feet wet with Suitscript. I made a script to set the bank account on refunds automatically…..

    Code:
    setRefundAccount()
    {
    nlapiSetFieldValue('account', 115, null, true);
    }
    It is set to the form on Page INIT. I just wanted to know, how would it be set up to just set the field once on creating the record and then not reset the field when the record is reopened again? Example: If the field had a different account initially and someone reopened the record and wanted to keep the original field.

    Thanks
    This is a cached copy. Click here to see the original post.

  • #21455

    khultquist

    It sounds like you've created a Client script, you might want to consider this as a User Event script, which gives you the ability to limit to type=create.

    If you want to stick with a client script, there are a couple ways to do what you want. You can check to see if the field is empty, and then set it (see below). Or you could look for another field (something like createdby) that tells you if the record is new.

    Code:
    setRefundAccount() {
    var account = nlapiGetFieldValue('account');
    if (!account) nlapiSetFieldValue('account', 115, null, true);
    }

  • #21456

    pcutler

    As mentioned, you could consider using a user event script as well. But as a client script, just call your function as follows:

    function myPageInit(type) {

    if(type == 'create') {

    setRefundAccount();

    }

    }

  • #21457

    Mikemacx

    Ahhh Yes…….

    Code:
    function setRefundAccount()
    {
    var recordid = nlapiGetFieldValue('tranid');
    if(recordid == "To Be Generated") { nlapiSetFieldValue('account', 115, null, true);
    }
    }
    Thanks for putting me on the right path……

You must be logged in to reply to this topic.