Disable line item Fields on Custom Transaction Form - netsuite

1)Want to disable line item fields on Custom Transaction form.
Below is the snippet I tried & applied to the form's custom code on LINE INIT FUNCTION function but it doesn't work. Does it work or is it a bug or something I am missing here.Please suggest
function lineInit(){
if(type == 'item'){
var itemDisFields = ['description','location'];
for(var i = 0; i < itemDisFields.length; i++){
nlapiDisableLineItemField('item',itemDisFields[i] , true);
}
}
}
2)How to freeze Add button in the line level.

Sublist indices in SuiteScript 1.0 start at 1, not 0, so you'll need to start i at 1.
I am not exactly sure what you mean by "freeze" the Add button, but there is no supported way to do this. You could of course hack it with jQuery. The best supported way to prevent a line from being added is to use a validateLine handler and return false from it when the line should not be added.

Related

Applying logic to button Make Copy - Netsuite

I just started with Netsuite and Suitescript 2.1. I am wondering if I can apply any logic to the "Make Copy" button via suitescript.
The make copy button is on the opportunity > sublist Item > Line item.
Examples of what I want to do:
Reset certain fields of the copied line
Fill in certain fields of the copied line (with a certain logic
behind it)
I already found a solution. I use the validateLine function. When making a copy of a lineitem in Netsuite the lineitem field: "line" has an empty string value until the line is created by clicking the "Add" button or clicking outside of the copied lineitem. I will check if that field is empty, if yes it means the line is a copy. Afterwards I can also set a custom field isCopy = true.
const lineIsCopied = () => {
let lineNumber = opportunity.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'line'
});
if (lineNumber) {
//linenumber is existing this means line is not a copy
return false;
} else {
//linenumber is empty this mean line is a copy
return true;
}
};
Try the 'validateInsert' within a Client Script.
Make sure your function return 'true' for a valid insert, otherwise any insert for any sublist won't succeed.

Suitescript 2.0 Get Button on a sublist

I have an older Suitescript 1.0 user event script where on the BeforeLoad I change a label on a button in a sublist. (note this is a button on the sublist not on the main header of the form
In order to do that I did something like this:
function changePackageContentsButtonLabel(type, form, request)
{
var mySublist = form.getSubList('recmachcustrecord_tst_my_sublist');
if(mySublist != null)
{
var NewButton = mySublist .getButton('newrecrecmachcustrecord_tst_my_sublist');
if(NewButton != null)
{
NewButton .setLabel('New Label Text');
}
}
}
that worked fine in that i could find the button based on a call to the sublist.getButton
In 2.0 I was wondering how to do that.
I had thought i would call the getButton that is based off the context.form but it does not seem to find the button in that case. And though there are methods to addButton on a sublist, there does not appear to be a getButton on it. I know i could use JQuery but that may be a bit more brittle it seems.
In the Netsuite help section search for
SuiteScript 1.0 to SuiteScript 2.0 API Map
After you get the button object, use label property to get or set a value for the button label.
var myButton = form.getButton({
id : 'buttonid'
});
myButton.label = "New Label Text"
I ended up having to put the logic I wanted into a client script and called it off of the pageInit. What I had to do was use native javascript and locate the button (by document.ElementById() and when i got that element I was able to change the value. This was not the desired way but it seems that 2.0 does not allow you to locate a button on a sublist like 1.0 did.

pdfkit nodejs, one element per page from page 2

Im using pdfkit to generate pdf invoice.
When all my content fit in one page I have no issue.
However when it doesn't fit and need an extra page, I have a strange behaviour:
Instead of adding the elements in the second page, it only add one line and the rest of the page is blank.
Then on 3rd page I have another element, and the rest it blank, then 4th page, 5th etc.
Here is the code corresponding to this part:
for (let i = 0; i < data.items.length; i++) {
const item = data.items[i];
this.itemPositionY = this.itemPositionY + 20;
if (item.bio) this.containBioProduct = true;
let itemName = item.bio ? `${item.item}*` : item.item;
this.generateTableRow(
doc,
this.itemPositionY,
itemName,
"",
this.formatCurrency(item.itemPriceDf.toFixed(2)),
item.quantity,
this.formatCurrency(item.itemPriceTotalDf.toFixed(2))
);
this.generateHr(doc, this.itemPositionY + 15);
}
Basically I just iterate over an array of products. For each line my Y position has +20.
Thanks for your help.
In case someone has this issue, here is a solution:
Everywhere in the code I know that an extra page could be generated, I add this:
if (this.position > 680) {
doc.addPage();
this.position = 50;
}
It allows you to control the generation of new pages (instead of pdfkit doing it automatically with potential problems)
You just need to track the position from the initialization of "this.position".
In that way, evertime it's superior than an Y position (680 in my case, it's a bit less than a page with pdfkit), you just do "doc.addPage()", which will create another page, and you reinitialize your position to the beginning of the new page.

NetSuite Update Customer subscription entries

I'm triing to update customer subscriptions list in netsuite.
var itemCount = recLead.getLineItemCount('subscriptions');
for (var i = 1; i < itemCount; i++ ) { recLead.setCurrentLineItemValue('subscriptions', 'subscribed', 'T');}
But error throws:
Notice (SuiteScript)
You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.
If you are planning on using the "current" line item function, then you do need to select the line to use. As below:
var itemCount=recLead.getLineItemCount('subscriptions');
for(var i=1;i<=itemCount;i++){
recLead.selectLineItem('item',i);
recLead.setCurrentLineItemValue('subscriptions','subscribed','T');
recLead.commitLineItem('item');
}
Alternatively, if you do not want to do it that way, you can use setLineItemValue, instead.
var itemCount=recLead.getLineItemCount('subscriptions');
for(var i=1;i<=itemCount;i++){
recLead.setLineItemValue('subscriptions','subscribed',i,'T');
}
Both, effectively, work the same.
BTW, since you have to start at row 1, you need to make sure you use i<=itemCount. Otherwise, if there are 10 rows, you will miss the last row. When you move to 2.0, and start your count at 0, you can use i< itemCount.
Before using setCurrentLineItemValue, you need to select the line using selectLineItem then commitLineItem to save the changes.

How to Remove the addPreSearch Filter

I am trying to remove the PreSearch filer and my code is as below. How can I achieve the same?
Xrm.Page.getControl("productid").removePreSearch(function () {
Object
});
Xrm.Page.getControl("productid").addPreSearch(function () {
fetchxml2();
});
function fetchxml2() {
var fetchXml1 = "<filter type='and'>"
fetchXml1 += "<condition attribute='productid' operator='in' >";
for (var i = 0; i < Itemid.length; i++) {
fetchXml1 += "<value>" + Itemid[i] + "</value>";
}
fetchXml1 += "</condition>";
fetchXml1 += "</filter>";
Xrm.Page.getControl("productid").addCustomFilter(fetchXml1);
//Xrm.Page.getControl("productid").removePreSearch(fetchXml1);
};
In order to be able to remove the handler via removePreSearch, avoid using an anonymous function by creating a named function and using that in both addPreSearch and removePreSearch:
function preSearchHandler(){
fetchxml2();
}
Xrm.Page.getControl("productid").removePreSearch(preSearchHandler);
Xrm.Page.getControl("productid").addPreSearch(preSearchHandler);
Just wanted to add this to the discussion:
If you, say, have three different custom filters on a lookup field, the functionality will stack when you apply a new filter.
For example, if you have an option set that calls addPreSearch() on the field, if you select all three different options, you will have all three filters applied to the field simultaneously.
say the option set has three options of [option A, option B, option C],
the corresponding functions are, for simplicity [filterA, filterB, filterC],
on the change event of the option set, for each filter that you apply, simply remove the other two (in this case).
if (optionSet == 810500000) {//option A
Xrm.Page.getControl('lookup').addPreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}
else if (optionSet == 810500001) {//option B
Xrm.Page.getControl('lookup').addPreSearch(filterB);
Xrm.Page.getControl('lookup').removePreSearch(filterA);
Xrm.Page.getControl('lookup').removePreSearch(filterC);
}//so on and so forth
I hope this helps someone out, I was able to apply custom filters to a lookup based on four distinct selections and remove the "stackable" filters by addition and removal in this manner. It's a little ugly, but, hey, it works. At the end of the day, sometimes the most elegant solution is to just win, win win win win.
If you need more context (fetchXml) and such, I can post that, too...but it doesn't really go along with the point I was trying to make. These filters can be applied simultaneously! That's the main idea I wanted to convey here.

Resources