I am able to set 4 of the fields in the Tax Report...
# suitescript
m
I am able to set 4 of the fields in the Tax Reporting sublist tab. Region of Origin. Delivery Terms. Nature of Transaction Code and Mode of Transport. I need to un set them based on the line on an invoice. I can unset all of them in the UI, however, my script won't unset two of the fields Delivery Terms and Mode of Transport. All the fields are part of the tax bundle and are select fields. My logs show empty After un setting them but the invoice manages to retain the values. Anything I can try to resolve this?
Copy code
function beforeSubmit(context) {
    if (context.type === context.UserEventType.CREATE || context.type === context.UserEventType.EDIT) {
        const newRecord = context.newRecord;

        var hasInventoryItem = false;
        const lineCount = newRecord.getLineCount({sublistId: 'item'});
        for (let i = 0; i < lineCount; i++) {
            const itemType = newRecord.getSublistValue({
                sublistId: 'item',
                fieldId: 'itemtype',
                line: i
            });

            if (isInventoryItem(itemType)) {
                hasInventoryItem = true;
                break;
            }
        }

        if (!hasInventoryItem) {
            log.debug("No inventory items found, unset intrastat fields");

            const fieldsToUnset = [
                'custpage_country_of_origin_temp',
                'custbody_transaction_region',
                'custpage_delivery_terms',
                'custbody_notc',
                'custpage_mode_of_transport'
            ];
            fieldsToUnset.forEach(fieldId => {
                log.debug({title: `Before Unsetting ${fieldId}`, details: newRecord.getValue({fieldId: fieldId})});
            });

            // Unset the fields
            fieldsToUnset.forEach(fieldId => {
                newRecord.setValue({fieldId: fieldId, value: '' });
            });
            fieldsToUnset.forEach(fieldId => {
                log.debug({title: `After Unsetting ${fieldId}`, details: newRecord.getValue({fieldId: fieldId})});
            });
        }
    }
}
I noticed the custbody_x gets un set but not the custpage_x fields
a
custpage_x fields ... aren't fields on the context.newRecord in your before submit
they're clientside only fields that a client script would have access to from the FORM not the RECORD
you can't unset them, they don't exist, if there ARE fields with those values set they're being re-written to custbody_x fields in a client script somewhere and you need to use the custbody_x field ids to unset them in your UE script
m
Oh right. So custpage fields are only accessible using Client Side script?
a
right, they're not real fields on the record, they're just temporary fields on the form in the UI
they're not stored to the Database at all
if you DO want to store the data from those fields then you have to rewrite their values to ACTUAL fields (custbody or custentity or custrecord or ... you get it)
m
I can set them on the CS script, but I wanted to unset them in some scenarios in the UE script. So it sounds like I should be able to unset on the CS instead of the UE script.
Ah, so looks like I can set values against the custpage fields on the pageInit only but not in saveRecord.
b
you need to better understand how the fields are used by bundle. those fields could only be used for display purposes and the value stored elsewhere