I am attempting to set the trandate field on a Dep...
# suitescript
j
I am attempting to set the trandate field on a Deposit Application in either a beforeLoad or a pageInit. I have tried it both ways. The pageInit works in the UI but I need it to work in situations where the deposit application is being generated automatically. Below is the pageinit codeblock. Beforeload is the same but with rec = context.newRecord. I am not getting any error, it is just not setting.
Copy code
function pageInit(context) {
        const rec = context.currentRecord;
        let linecount = rec.getLineCount('apply');

        for (i = 0; i < linecount; i++) {
            let apply = rec.getSublistValue({
                sublistId: 'apply',
                fieldId: 'apply',
                line: i
            });
            log.debug('apply', apply)

            if (apply) {
                let applydate = rec.getSublistValue({
                    sublistId: 'apply',
                    fieldId: 'applydate',
                    line: i
                });
                log.debug('applydate', applydate);

                rec.setValue({
                    fieldId: 'trandate',
                    value: applydate,
                    ignoreFieldChange: true
                });
            }
        }

    }
n
Is the applydate logging? Have you tried using a try catch block to log errors?
j
I did and no errors were returned. The applydate is logging. And it is logging in the correct date format. When I have this pageInit active, it will change the trandate in the UI when I create a dep application manually.
n
can it be set on beforeSubmit?
j
Nope, tried that, too.
n
and I assume you are using rec.save() after setting the field?
I mean, you shouldn't have to on beforeSubmit in a UE script, so never mind
Last suggestion is to remove the ignoreFieldChange parameter.
j
Tried that and still no luck. I can't find other scripts or workflows that are overriding my work. I'm wondering if it has something to do with the timing of fields being set. Since the app deposit is happening in the background, my script might be running before the system has the chance the set the date. I'm starting to think I need to scrap this way of doing it and brainstorm a new way. Just no idea why it's giving me this trouble. NS is so fickle sometimes. Thanks for the suggestions!
n
Yeah no problem. Maybe log the rec after the field has been set to see if the date is there. If it is there, but is gone on after submit something must be overriding it.
j
I brought this on myself because I stupidly told accounting that this script would take me less than an hour to get done and working. 😄 I should never say something like that.
n
Ha, yeah NS will def punish you for that
b
first step would be to hardcode the trandate to a value, preferably in the past
the graduate to setting it to match a hardcoded line
finally graduate to setting it to whichever line you want
i expect you to learn on step one that before load is not appropiate