I’m working on a little util module to do some thi...
# suitescript
c
I’m working on a little util module to do some things that are repetitive tasks. For example, the snippet below to set multiple fields on a record from an object passed as a parameter. Another one I have is for issuing queries for datasets larger than 5000 records. Just wondering - has anyone else made or used any util/helper libraries to abstract away some of the more tedious suitescript functions?
Copy code
const setValues = (target_record, field_obj)=>{
    Object.entries(field_obj).forEach(([key,value])=>{
        target_record.setValue({
            fieldId: key,
            value: value
        })
    })
}
c
That function could fail too depending on the inputs for certain fields like dates
c
It works as long as the object passed is a javascript date object, but yeah if you just pass the string in it will throw an error
c
Yep. Just something to look at as someone who has run into this one before šŸ˜„. I recently created a library that lets you build custom suitelets using an object rather than code. You just describe the suitelet as a json object and it outputs the suitelet form.
šŸ‘ 1
c
Nice that sounds interesting!
c
So no code to create this UI. Just the JSON object and the render method I have.
I got so sick of writing suitelets that I just wrote this so i could write a quick JSON object and have a suitelet UI
suitelet_form_builder.js,suitelet_form_builder_constants.js
s
I tend to shy away from generalized functions like that
setValues()
unless there's a strong use case. In my experience a simple set of assignments is more clear and easier to maintain and customize. That said, I do use NFT so those assignments are literally
target.fieldname = input.someinputname
(which just in that one line represents s common divergence that would confound setValues()- the source object field name may differ from the target NS name)
c
You could maybe build the form builder I have into NFT if you don't have anything like that. Its honestly been pretty useful.
e
I went the same route @creece but instead of using a JSON object to build the suitelet, I used a custom record.
message has been deleted
s
We've tried to keep NFT focused on lower level general constructs but form-builder is definitely an idea for higher level reuse. To that end I could see a version of your form builder using NFT to help with record manipulation code. šŸ™‚
c
@Eric B How is the custom record stuff working out? Is it just to let end users try to manage the suitelet construction? Mine was targeted at a developer.
@stalbert I gotcha. Feel free to use whatever. If it helps it helps.
e
Yes @creece the goal was to allow an advanced user to be able to spin up a suitelet with half the work done in terms of code.
I even created a suitelet that allows end users specify those values that can be saved to the custom record.
c
Nice, that seems like it'd go well with my stuff as another option. Nicely done
šŸ‘ 1
e
The data can also be CSV imported into the custom record.