If you have custom list that you are deploying alo...
# suitescript
m
If you have custom list that you are deploying along with your code. Is it safer to try and convert the scriptid values to internalids when referencing list values? I have never read up on how lists are deployed from the objects but it seems like there would be no guarantee the same internalid would be assigned on deployment to a new environment.
a
1. I'm not sure how you would do that? you can't set your field values for list fields by referencing the script id you'd need the internal id 2. the list values are created in the order that the list items are in your custom list xml, so you can be sure they're 1,2,3 per whatever you created them as. ... actually, maybe that's only true if you have
<isordered>T</isordered>
, which I do for all my lists so that works for me 🙂
I also usually have lib object that maps the list ids to the actual values, so my code has meaningful text instead of magic numbers.
so then my code looks like
Copy code
if(varName === lib.ORDER_TYPE.NEW){...}
instead of
Copy code
if(varName === 1){...}
which is way more readable and doesn't require someone to double check what 1 refers to all the time.
m
Yeah if the list dependency is external to the script I often do something similar. I wasn't aware of the
<isordered>
that is helpful to know about. How I am doing the mapping is by just searching the list like this.
Copy code
const results = _cache_getListMapping.get({
            key: cache_key
            , loader: () => {
                const results = [];
                search.create({
                    type: list_id
                    , columns: ["internalid", "scriptid", "name"]
                    , filters: [{name: "isinactive", operator: <http://search.Operator.IS|search.Operator.IS>, values: "F"}]
                }).run().each((result) => {
                    results.push({
                        id: result.getValue("internalid")
                        , scriptid: result.getValue("scriptid")
                        , name: result.getValue("name")
                    });
                    return true;
                });
                return JSON.stringify(results);
            }
            , ttl: 30 * 60 // 30 mins
        });

        // cached values will be returned as a JSON string so we stringify all results and parse them before returning
        return JSON.parse(results);
And then I can convert back and forth from scriptid to internalid. If I want to get the scriptid from internalid.
Copy code
_.find(listmapping, (s) => s.id == variable_w_internalid)?.scriptid;
If I want to get the internalid from the scriptid.
Copy code
_.find(listmapping, (s) => s.scriptid === "VAL_*")?.id;
a
yeah that works too 🙂
m
I really just started doing this as I noticed that the scriptid is in the deployment xml. So I have yet to deploy a script with it to another environment.