This topic contains 12 replies, has 0 voices, and was last updated by hv85 7 years, 5 months ago.
-
AuthorPosts
-
March 31, 2017 at 8:56 am #21742
hv85Hi 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. -
March 31, 2017 at 11:42 am #21743
Vesku1980(function(){
var el = document.getElementById("ok");
el.addEventListener("click", function() {
alert ('Clicked!')
})
}());
-
May 12, 2017 at 2:57 am #21744
tect22Hi 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.
-
June 8, 2017 at 4:13 am #21745
hv85Hi 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
-
June 8, 2017 at 5:32 am #21746
micmix_88Hi 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
-
June 8, 2017 at 7:02 am #21747
micmix_88Ah 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?
-
June 19, 2017 at 8:21 am #21748
hv85Hi 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
-
June 20, 2017 at 12:17 pm #21749
pcutlerWhy 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.
-
June 20, 2017 at 12:24 pm #21750
khultquistI 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.
-
June 20, 2017 at 2:01 pm #21751
pcutlerOriginally 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.
-
June 20, 2017 at 2:28 pm #21752
khultquistHey thanks for that, I never realized there was a type = copy. I'll have to go back into my scripts and clean that up.
-
June 20, 2017 at 2:40 pm #21753
pcutlerGlad 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 -
June 22, 2017 at 6:38 am #21754
hv85Thanks 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
-
AuthorPosts
You must be logged in to reply to this topic.