This topic contains 12 replies, has 0 voices, and was last updated by hv85 7 years, 5 months ago.

  • Author
    Posts
  • #21742

    hv85

    Hi all,

    I'm trying to trigger the clear all lines button on a purchase request via a client side script. Is there a way to tap into this element via jQuery and trigger the onclick event? I tried:

    jQuery('#clearsplitsitem').click()

    But it doesn't work.

    Has anybody else managed to trigger a button click before in NS script or accessed the internal NS method behind a button?

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

  • #21743

    Vesku1980

    (function(){

    var el = document.getElementById("ok");

    el.addEventListener("click", function() {

    alert ('Clicked!')

    })

    }());

  • #21744

    tect22

    Hi hv85 ,

    You can achieve this by triggering the NetSuite Function for the button.

    For expense sublist: clear_splits('expense');

    For item sublist: clear_splits('item');

    Regards.

  • #21745

    hv85

    Hi tect22

    Thanks for your reply. I've tried loads of variants of this method and cannot get this function to trigger. Does it need to run against the record itself or within jquery? When I try to run it on its own it says clear_splits is not defined.

    Thanks for your help

  • #21746

    micmix_88

    Hi there,

    I have just added this as a function on the page..

    function removeAllLinesButton(type)

    {

    clear_splits('item'); return false;

    }

    Add this to the custom actions list and all should work.

    N.b. Add the script file on the form to the custom code field… You dont need to fill out the options below it as it is called from the button.

    Hope this helps.

    Mike.


    hv85 replied on 06/08/2017, 06:03 AM: Thanks Mike,

    I already have the button on the form and wish to clear all of the existing lines programmatically, rather than rely on the user. Basically a copy of an original purchase transaction is being created and I want to wipe out the line items making the user put in new ones so we don’t end up ordering the same stuff again accidentally.

    Hope that makes sense!

    Holly

  • #21747

    micmix_88

    Ah right, do you want to remove all lines on the initialise of the record? So before the user has access to the record you want to make sure there are no lines on it?

  • #21748

    hv85

    Hi micmix_88 ,

    Yes this is how we want it to work. We are in effect creating a variation order to the original so we don't want the original items being ordered again.

    Any help is much appreciated

  • #21749

    pcutler

    Why wouldn't you do this server-side? This can be accomplished easily in a before load user event script:

    function beforeLoad()

    {

    for(var linenum = nlapiGetLineItemCount('item'); linenum > 0; –linenum)

    {

    nlapiRemoveLineItem('item', linenum);

    }

    }

    Also, even if you do use a client side script I would still recommend the same approach. Using unpublished API methods such as clear_splits() introduces unnecessary upgrade risks every six months. If you're concerned about triggering client-side events, SuiteScript 2.0's Record.removeLine(options) accepts a parameter for options.ignoreRecalc to prevent the recalc event from triggering.

  • #21750

    khultquist

    I agree with pcutler this should be done server side, avoiding unpublished API.

    The trick on server side is to trigger the script only after once, when the copy button is used, otherwise the script will clear all lines every time that you edit the record. I believe you can use nlapiGetRecordId() to determine if this is a new record, and have a conditional in beforeLoad.

  • #21751

    pcutler

    Originally posted by khultquist

    View Post

    I agree with pcutler this should be done server side, avoiding unpublished API.

    The trick on server side is to trigger the script only after once, when the copy button is used, otherwise the script will clear all lines every time that you edit the record. I believe you can use nlapiGetRecordId() to determine if this is a new record, and have a conditional in beforeLoad.

    Agreed, it's important to add conditions for the specific scenario you're trying to target. The before load method has a "type" parameter, so to do this for all record copies, wrap the logic up in a if(type == 'copy') block.

  • #21752

    khultquist

    Hey thanks for that, I never realized there was a type = copy. I'll have to go back into my scripts and clean that up.

  • #21753

    pcutler

    Glad it was helpful! Here's the full list of before load execution context types from SuiteAnswer 10635 (there are different execution types for before and after submit, also listed in the SuiteAnswer):create
    edit
    view
    copy
    print
    email
    quickview

  • #21754

    hv85

    Thanks for the info everyone much appreciated.

    As the code for the variation purchase order has been written by external suppliers in client side script I will try to see what I can do on the before load event, hopefully without breaking any of the functionality

You must be logged in to reply to this topic.