hoping to get thoughts from folks this morning, si...
# suitescript
s
hoping to get thoughts from folks this morning, since original post was late last night?
s
I can only say I've learnt that not all transactions are built the same, and they shouldnt be treated equally. if functionally it's required to script, i'd script, seems like occams razor....
w
Shouldn't something simple like this suffice?
👍 1
s
Yes, @Watz - I was just hopeful someone knew of a shortcut or perhaps there was something I missed like
sublist.rowsFromSearch( searchid )
that turned that nearly 50 lines of code above into 1 🙂
w
Isn't that a possibility too? I remember reading(?) something about it. Maybe it's only in suitelets.
(now it's only 22 lines 😂 )
I'm probably thinking about List.addRows()
s
aye, or maybe there was something from SS1.0 that made me think this was possible natively. I was hoping not to introduce another script but it sounds like it's the only option and NS doesn't provide any shortcuts (i.e. we have to build out manually - no special support for the presumed common use case of a saved search as source for sublist rows)
w
I'm sure that NFT can help you 😉
s
it can definitely help shorten the code above, but can't escape code altogether!
😄 1
n
@stalbert You are thinking of nlobjSublist.setLineItemValues(values) This allowed you to add search results to a sublist without iterating the results / setting each column individually. There is, unfortunately, no SS2.0 equivalent. Here's the SS1.0 snippet from NS Help, mayb eyou can make use of this if you're happy to go with 1.0
Copy code
function beforeLoadSublist(type, form)
{
    if (type=='edit' || 'view')
    {
        //add a sublist to the form. Specify an internal ID for the sublist,
        //a sublist type, sublist UI label, and the tab the sublist will appear on
        var contacts = form.addSubList('custpage_contacts', 'staticlist', 'Custom Contacts', 'general');

        //add fields to the sublist
        contacts.addField('entityid', 'text', 'Name');
        contacts.addField('phone', 'phone', 'Phone');
        contacts.addField('email', 'email', 'Email');

        // perform a Contact record search. Set search filters and return columns for
        // the Contact search
        var contactdata = nlapiSearchRecord('contact', null, new
                          nlobjSearchFilter('company', null, 'anyOf', nlapiGetRecordId()),
                            [new nlobjSearchColumn('entityid'), new nlobjSearchColumn('phone'),
                            new nlobjSearchColumn('email')])

        // display the search results on the Custom Contact sublist
        contacts.setLineItemValues(contactdata)
}
}