Please can I have suggestions on why I cannot add ...
# suitescript
c
Please can I have suggestions on why I cannot add a particular item to an invoice in SS2? This is my code:
Copy code
rec.selectNewLine({
    sublistId: 'item'
});

rec.setCurrentSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    value: lineData.itemInternalId
});
This error occurs on the second statement above:
Copy code
"type":"error.SuiteScriptError","name":"INVALID_FLD_VALUE","message":"You have entered an Invalid Field Value 25542 for the following field: item"
The error happens for that item internal id only. If I use other item internal id values then the line is added and the invoice is created successfully. If I create the invoice manually for the same customer and location then I can add the item without issue. I welcome all suggestions of what to check for.
n
Can you please verify the subsidiary of the Item and Customer?
Also, can you check if the item is inactive or not?
c
I should say that the item is "Other Charge for Sale"
n
can you check if the item is inactive or not?
c
It's not inactive (remember that I can add it to an invoice manually - the error only happens in my Suitelet)
Checking subsidiaries again...
n
Yes, you can add it manually.
but the script does not allow you to add. That's why I am asking you to verify if the item is inactive or not.
c
It's not inactive
n
What about subsidiary?
c
Subsidiary is exactly the same as other items that my script can add to the invoice
k
@cja is lineData.itemInternalId a String by any chance?
Check the typeof?
c
The JSON is like this:
Copy code
{
  "itemInternalId": "25542",
  "quantity": 1,
  "rate": 0.05,
  "amount": 0.05,
  "vatAmt": 0,
  "grossAmount": 0.05
}
I will check the typeof now
k
That would be why. I would have said it’s a string.
use
parseInt(lineData.itemInternalId)
c
I will test as you say, but here's a line that is added successfully:
Copy code
{
  "itemInternalId": "25439",
  "quantity": "1.00000000",
  "rate": 3,
  "amount": 2.5,
  "grossAmount": 2.5
}
k
hmmmm and the only difference its the item type?
c
Well, when I diff the XML for the bad record and a good record there are lots of differences, but I can't make them identical
So I'm looking for common things to check
k
Those Quantity values look a bit different
c
They are, but the code doesn't get to there. The error is on this statement:
Copy code
rec.setCurrentSublistValue({
    sublistId: 'item',
    fieldId: 'item',
    value: lineData.itemInternalId
});
I haven't set any other item line fields yet
k
In console can you manually set the item to the id 25542
c
I've never done anything in the console with NS before. How do I do that?
k
Easiest is with SS1.0
c
I changed the code to the following and got the same error:
Copy code
rec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: lineData.itemInternalId.toString()
        });
k
did you try the parseInt
c
Trying now
Same error on the same item. So it's happy to add the preceding item (25439) whether the id is string or number but rejects the bad item (25542) regardless of type
k
That is odd.
Is this the only other charge item?
c
Probably not. Looking now...
There are several more. You going to suggest I try one of them?
k
yes. Just to see if that is the common denominator
I would have said it is.
c
Same error with another Other Charge item
But why does it work when I add it in the UI?
k
I would have it is the other charge items not going on.
To be fair i have no idea but that seems to be the issue.
c
It looks like it
k
If it adds normal items no problem then gotta be the type.
c
Thank you for your help. If you have any other ideas I will be grateful
k
Do you have full NS Support?
b
is the custom form used in the script the same as the ui?
c
Good idea. Checking...
@karlenigma Yes, that'll be my last resort on this since it's urgent
(Imagine if we had to pay to be members of this Slack account! It's certainly not less valuable than NS phone and email support)
k
I would pay!!
c
Me too, but it should be very expensive!
@battk I've created the invoice manually again making sure I'm using the same custom form as my code and I can add the item to the invoice
s
Best advice for getting fastest help from support on script issues. Create a very small scheduled script, with as few lines of code as possible, to reproduce the issue. Then attach it to the case. It helps them focus on the problem, and not get distracted by other things going on in your larger script.
c
@scottvonduhn Thanks, that's good advice
b
i say make the suitelet run as administrator
and give it another try
c
Now that's a good idea. Doing it now...
b
i doubt the problem is that the value is the wrong type. Its likely thats its simply not a valid option
c
Same error when the Suitelet's role is Administrator
Ok, with time short, let me approach this problem from another angle: I am using the Other Charge item to represent a payment provider (Square) processing fee. Can anyone suggest another item type for this, in case the problem is that it's Other Charge?
n
You can create a Non-Inventory item and use it as a processing fee as an alternate solution since of the other worked.
c
Thank you, I am doing that now
And that is working
k
Gotta be Other Charge for some reason then.
c
I think it's likely, although it could be something else about the items I'm trying, but I've no time to experiment further