Hey all, I can't get a UE script on afterSubmit e...
# suitescript
c
Hey all, I can't get a UE script on afterSubmit entry point to set the value of the authcode field on customer payments. The code seems to be working fine, but the change just isn't sticking. What am i missing??
Copy code
define(['N/search', 'N/record'],
     function(s, r) {
         function afterSubmit(context){
             try {
                var pm = context.newRecord.getValue({fieldId: 'paymentmethod'})
                log.debug({title: 'payment #', details: pm})
                if(!(pm == 110 || pm == 111 || pm == 109 || pm == 8)) {
                    return
                }
             } catch(e) {
                log.debug({title: 'error', details: e})
                return
             }
            
            try {
                var ptId = context.newRecord.getValue({fieldId: 'custbody_ng_paytrace_data_ref'})
                var recId = context.newRecord.getValue({
                    fieldId: 'id'
                })               
                var ptLookup = s.lookupFields({
                    type: 'customrecord_ng_paytrace_ref',
                    id: ptId,
                    columns: ['custrecord_ng_ptr_approval_code']
                })
                var rl = r.load({type: r.Type.CUSTOMER_PAYMENT, id: recId})
                rl.setValue({fieldId: 'authcode', value: String(ptLookup.custrecord_ng_ptr_approval_code)})
                rl.save()

                log.debug({title: 'Auth Code', details: context.newRecord.getValue({fieldId: 'authcode'})})
                log.debug({title: 'paytrace record ID', details: ptId})
                log.debug({title: 'Pay trace Authorization Code field value', details: ptLookup.custrecord_ng_ptr_approval_code})
                log.debug({title: 'Payment Record ID', details: recId})


            } catch (e) {
                log.debug({title: 'error', details: e})
            }
            


         }
         
         return{
            afterSubmit: afterSubmit
         }
     })
When it logs the authcode field from the payment record, it shows it as the correct value, but when i open the record manually to confirm, the field is blank.
b
it will follow the same rules as the ui, so try editing the customer payment and set the auth code on it
id also recommend using a before submit user event scripts if possible
your code will basically double customer payment save time
c
A simple test to determine that i'm wasting my time, it clears it out in the UI as well. Thanks for that.
b
you should at least make sure that you can mark the cc approved checkbox
you cant have an authcode for an unapproved payment
c
We recently switched to paytrace for our credit card processing, and i believe scripts in their bundle are responsible for the behavior. The CC approved field is actually disabled now
b
last attempt would be making sure your script deployment runs last and set the field in your code
c
It's last, yeah. I'll instead make a custom field and set the value with submitFields there and hope that works. This is only to get the authorization code to show on the print form. paytrace stores it in a custom record, and i couldnt get the form to pull the value from it's new home. This is just a quick fix for now, until we can figure something better out
Thanks for your help @battk!