The getSublistSubrecord call doesn't appear to be ...
# suitescript
c
The getSublistSubrecord call doesn't appear to be grabbing the newly created line. A new line gets added at the end of the sublist but it is not set to default. Anyone know how to add a new address and set it as default?
b
@Craig insertLine doesn't return the line, you would need to use setSublistValue and specifiy the line number
If you're working with a record in standard mode (not dynamic) you don't need the insert line either unless you're intentionally trying to move the other lines up by one
c
I don't want to use insertLine then
I'm not clear how to set the default flag
the address is on a sublistSubrecord but from there I need to get the list one level above
b
one sec, writing a snippet
Sorry that took a sec, started writing in the slack snippet window and then moved to WebStorm because it was going slow here. There's many ways to do it, but this would grab the line count and then use that for the new lines. Since line count is number of lines, and then line # is zero indexed, line count == the next index
Does that all make sense? Not sure on your experience level, I can explain more if you'd like
c
Yeah that's much simpler than mine
just refactored that into my larger function and it works great
I was trying to set it on line 0 so the default address is at the top but I don't think that really matters
It works perfectly now - full function for reference. customer record is actually saved in another function.
b
@Craig Cool, looks good. And yeah, if you wanted to put the address at the top you should be able to use insertLine at line 0 and then set line 0 instead of using the addressLineCount throughout. Insert line just doesn't return the line which is why your original wasn't working
This should work if you wanted it to be the first line. I admittedly never use insertLine unless I'm working with a dynamic record but it should work as shown.
d
This discussion has been useful, thanks! Here's a pattern I'm using for mapping values onto a range of fields (can use for address subrecord, transaction body fields and sublist fields). I find defining this mapping object of
fieldId:value
very easy to read and maintain
c
@David B Your code comments states that the country must be set first, I'm not seeing the need for that? I'm setting it last.. is there something I should be aware of?
b
country first
otherwise you risk losing data if the address form changes
☝️ 1
c
I don't fully understand the explantation in the help text
I've made that change though
b
make a custom address form for Afghanistan
make a new address in the ui, set all the fields except country
set the country to Afghanistan last to see what happens
c
Got it
b
Good callout @battk and @David B I always forget about that and then it bites me.
d
One other cool thing you can do is use getters in your object. For example on a Sales Order,
custcol_baseprice
holds the item's base price at the time of order entry. This is populated by setting the item and then getting the price in the
rate
field. As we don't know ahead of time what that price is (without doing a search), we use a getter to get it from
getCurrentSublistValue(…)
price
(aka "Price Level") is also calculated with a getter; "Base Price" (1) if
item.unitprice
is the same as the default
rate
, and "Custom" (-1) if otherwise
s
<cough> NFT <cough>
👀 1
b
@David B Why the delete this.custcol_baseprice? In case it was set by something else previously? Interesting pattern though, thanks for sharing, I've heard of getter/setters but haven't used them so will give this a shot next time there's an opportunity
d
@stalbert
Error: The element type "cough" must be terminated by the matching end-tag "</cough>"
😉 1
@bbahrman
custcol_baseprice
is referenced twice, once when the field is set, then again by the
price
getter. By using
delete this.custcol_baseprice;
and then returning a value, you remove the getter and replace it with the value; so
getCurrentSublistValue(…)
ends up only being called once
b
Ah, I see that now, thanks @David B
👍 1