Hello all. We are starting to use discount items a...
# suitescript
a
Hello all. We are starting to use discount items and want reporting capabilities driven from the items being discounted. There is no way to accomplish this using saved searches. I saw this is an enhancement (273627) on SuiteAnswers (36477) NS has provided a code snippet to help with this but I cannot get it to work. Below is what NS posted (which has an error in the for loop: "a" is not declared as a variable). Even after fixing this, the script does not function. I have tried both Client and User Event (Page in it, Save Record, Before submit. . . ) Needless to say, I have lost confidence in NS resolving this issue. Can anyone impart some wisdom on resolving this issue? Thank you.
Copy code
var cTranId = nlapiGetRecordId();
var filters = new Array();
filters[0] = new nlobjSearchFilter('internalid', null, 'anyof', cTranId); //internal id of the transaction record

var columns = new Array();
columns[0] = new nlobjSearchColumn('item');

var b = new Array();

var ss = nlapiSearchRecord('transaction', null, filters, columns);

for (a = 0; a < ss.length; a++) {
    var item1 = ss[a].getValue(columns[0]);
    if (item1 == 115) { //115 was the internalid of a sample discount item
        nlapiSetLineItemValue('item', 'custcol_applied', a, ss[a - 1].getText(columns[0]));
    }
}
e
You'll need to commit the line after you set the value in order for it to update the field in the database.
a
. . . crazy how much scripts mimic the UI interaction. Thank you @Eric B. I will give that a go.
n
interesting that it starts the loop at zero, lines are not zero indexed in SS1.0 are they?
a
I am so lost here. I am not a developer, but I thought you also need to select the line first.
n
Pretty sure if you use setLineItemValue, you don't need to commit. if you use set*Current*LineItemValue you need to first select the line and then after setting the value "commit" the line. If you're not a dev, and not experienced with the api you're going to get lost fast on this.
e
Yeah lines are not zero indexed in SS1.0 so that needs to read for (var a = 1 which the only way the ss[a-1] would make sense.
a
@Eric B Okay, let mecheck that out. Thanks.