NetSuite Update Customer subscription entries - netsuite

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.

Related

Disable line item Fields on Custom Transaction Form

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.

Netsuite - Set Line Item Value

I am trying to figure out how to set a custom value item from the value of another field on the item field. I am not getting any errors, but it is not changing the value.
Here is the code:
function validatePOLineItem(type){
if(type == 'item'){
for (var i = 0; i <= nlapiGetLineItemCount('item'); i++) {
// Get the value for amount on the item line
var amount = nlapiGetCurrentLineItemValue('item', 'amount');
// Get the value for the PO Amount on the item line
var po_amount = nlapiGetCurrentLineItemValue('item', 'custcol_po_amount');
// Set PO Amount equal to Amount on the item line
nlapiSetCurrentLineItemValue('item', po_amount, amount);
}
}
}
Looks like you left off the column name you are trying to set. Also, you should just have to update the "current" lineā€¦
function validatePOLineItem(type){
if(type == 'item'){
var amount = nlapiGetCurrentLineItemValue('item', 'amount');
nlapiSetCurrentLineItemValue('item', 'custcol_po_amount', amount);
}
}
Is this a client side script or a user event script? If it is a client side script that is deployed on the validate line event, then you do not need to do a loop. Since the function will trigger every time a line is added. Also you will need to add 'return true' as the last line for the line to be added.
You cannot manipulate the amount field programmatically. You need to modify the quantity or the rate instead. If you are trying to apply a discount or something like that, then I recommend using NetSuite's Discount Items or Promo Codes mechanisms.
Question: Why do you need to have a loop if you are just dealing with the current line item?
Suggested Solution: If you want to achieve it, you can set the Rate equal to 'custcol_po_amount' but this will only work if the quantity is 1 and assuming that the value on 'custcol_po_amount' is accurate.

remove previously added and() clause from Where com.datastax.driver.core.querybuilder.Select.Where

for (int i=0; i<mycolumns.length; i++)
{
where.and(QueryBuilder.eq(COLNAME, mycolumns[i]));
//how to remove the above and() call
}
In every iteration of the loop, I want to execute the query and then substitute the value in next loop iteration.
I'm not completely clear on what you are trying to accomplish. I am guessing that you are trying to update multiple rows sharing a primary key, updating 1 row at a time?
Unfortunately this isn't possible since when you call where.and you are adding data to the Where object and it is returning you a reference to the same Where object.
In short, Where is not immutable and neither is the Statement it belongs to, so you won't get a new copy every time you call it, rather you get an updated version of the Where object.
What you could do is generate your Statement again (whether it be QueryBuilder.update,delete, or insert) in the loop like:
for (int i=0; i<mycolumns.length; i++) {
Statement stmt = QueryBuilder.update("tableName").where(eq("key", 1)).and(QueryBuilder.eq(COLNAME, mycolumns[i]));
session.execute(stmt);
}

Highlight Duplicate list item in SharePoint 2013

I have a SharePoint 2013 (The Cloud version) custom list where 1 column is a text field where contact numbers are keyed in.
How can I get SharePoint to highlight duplicate values in that column so that every time a new item is added to the list, I'll know if the contact number has been used previously?
Ideally, here's what I'd get if I were to enter 816's details for the 2nd time:
CNO....Name.......Issue
816.....Blink........Login Problem (highlighted in red)
907.....Sink.........Access Denied
204.....Mink.........Flickering Screen
816.....Blink........Blank Screen (highlighted in red)
I've been struggling with this for awhile and would be very grateful for any advice. Thanks!
Since SharePoint 2013 uses Client Side Rendering (CSR) as a default rendering mode I would recommend the following approach. Basically the idea is to customize List View on the client side as demonstrated below.
Assume the Requests list that contains RequestNo column.
The following JavaScript template is intended for highlighting the rows when list item with RequestNo column occurs more then once:
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var rows = ctx.ListData.Row;
var counts = getItemCount(rows,'RequestNo'); //get items count
for (var i=0;i<rows.length;i++)
{
var count = counts[rows[i]["RequestNo"]];
if (count > 1)
{
var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
var tr = document.getElementById(rowElementId);
tr.style.backgroundColor = "#ada";
}
}
}
});
function getItemCount(items,propertyName)
{
var result = {};
for(var i = 0; i< items.length; i++) {
var groupKey = items[i][propertyName];
result[groupKey] = result[groupKey] ? result[groupKey] + 1 : 1;
}
return result;
}
How to apply the changes
Option 1:
Below is demonstrated probably one of easiest way how to apply those changes:
Open the page in Edit mode
Add Content Editor or Script Editor web part on the page
Insert the specified JavaScript template by enclosing it using
script tag into web part
Option 2:
Save the specified JavaScript template as a file (let's name it duplicatehighlight.js) and upload it into Site Assets library
Open the page in Edit mode and find JSLink property in List View web part
Specify the value: ~sitecollection/SiteAssets/duplicatehighlight.js and save the changes.
Result
SharePoint has some basic conditional formatting for Data View Web Parts and XSLT List Views, but the conditions you can use are rather limited. You can compare a field in the current item with a value that you specify. There are no formulas to count the number of items with the same name or similar, which would be the approach to use to identify duplicates.
If you need to identify duplicates, you may want to create a view that groups by the CNO number. Grouping will also include an item count, so you can run down the list and spot groups with more than one item.

How to get all internal ids of one custom record

I'm doing Netsuite integration with Java so I've created one custom record test and it has custom fileds x, y, z...
I entered some test records, and now I want to get all test records when I give Internal id of test.
Currently I'm passing internal ids of all records but I want by using main internal id(626) .
How to get all these internal ids(101, 202).
CustomRecordRef[] customRec = new CustomRecordRef[3];
String[] internalIds = {"101", "202"};
for (int i = 0; i < 2; i++)
{
CustomRecordRef crr = new CustomRecordRef();
customRec[i] = crr;
crr.setTypeId("626");
crr.setInternalId(internalIds[i]);
}
How do I get those?
Have you tried CustomRecordSearch? If you want them all then the only filter you should need to set is recType in the CustomRecordSearchBasic. I believe you are saying your custom type 'test' has an internalId of 626 which is what you want to use for recType.internalId.
Records in NetSuite contain a function called getAllFields - cust.getAllFields() - not sure if that will work as a method in java. Returns an array with all fields.

Resources