Hi! Is it possible to change the status of this in...
# suitescript
s
Hi! Is it possible to change the status of this invoice to "não pago(not paid)"? It says "pago(paid)", but I want to change it to "não pago(not paid)". Can anyone help me with this?
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType MapReduceScript
 */

var status = {
    disponivel: 1,
    gerado: 2,
    confirmado: 3,
    rejeitado: 4
}

define(['N/search','N/record'], function(search, record) {

    function getInputData() {
        return search.create({
            type: 'invoice',
            filters:
            [
                ["mainline","is","T"], 
                //"AND", 
                //["trandate","within","12/09/2020","13/09/2020"],
                "AND", 
                ["installment.custrecord_rsc_cnab_inst_status_ls", "anyof", [status.disponivel]],
                "AND",
                ['internalid', 'anyof', 
                    [
                        4694248,
                        4722798
                    ]
                ]
            ],
            columns:
            [
                search.createColumn({ name: 'internalid', label: 'Internal Id' })
            ]
        })
    }

    function map(context) {
        var contextValue = JSON.parse(context.value)
        var invoiceId = contextValue.id
        var invoice = record.load({
            type: record.Type.INVOICE,
            id: invoiceId
        })
        
        const lineCount = invoice.getLineCount({
            sublistId: 'installment'
        })

        for (var i = 0; i < lineCount; i++) {
            var currStatus = invoice.getSublistValue({
                sublistId: 'installment',
                fieldId: 'custrecord_rsc_cnab_inst_status_ls',
                line: i
            })

            if (currStatus == 1) {
                continue
            }

            invoice.setSublistValue({
                sublistId: 'installment',
                fieldId: 'custrecord_rsc_cnab_inst_status_ls',
                line: i,
                value: status.disponivel
            })
        }

        invoice.save()

        log.audit({ title: 'Registro atualizado', details: invoiceId })
    }

    function reduce(context) {
        
    }

    function summarize(summary) {
        log.debug('Summary Time','Total Seconds: ' + summary.seconds)
        log.debug('Summary Usage', 'Total Usage: ' + summary.usage)
        log.debug('Summary Yields', 'Total Yields: ' + summary.yields)
        
        log.debug('Input Summary: ', JSON.stringify(summary.inputSummary))
        log.debug('Map Summary: ', JSON.stringify(summary.mapSummary))
        log.debug('Reduce Summary: ', JSON.stringify(summary.reduceSummary))
        
        //Grab Map errors
        summary.mapSummary.errors.iterator().each(function(key, value) {
            log.error(key, 'ERROR String: ' + value)
            return true
        })
    }

    return {
        getInputData: getInputData,
        map: map,
        reduce: reduce,
        summarize: summarize
    }
})
j
The standard status field is calculated based on the payments/credit applied to the invoice. So you can only change it by applying or removing payments/credits from an Invoice. Your script is actually just getting specific invoices and updating custrecord_rsc_cnab_inst_status_ls.
s
So I want to change the status because they want to delete these invoices. However, netsuite is not allowing them to be paid, but there is still value in debits. For example, that invoice has not been paid but is reported as paid. They want to change the status to unpaid, to try to delete the invoice. @Juliano Oliveira
s
Status is a native field, not sure what custom field you are editing.
You need to remove the payment applications and the invoice will go back to unpaid
s
How to remove? @Sandii
@Sandii I'm trying to edit this field:
s
Based on SA 100295, I assume these are term installments related to the Brazilian Hub SuiteApp ? https://netsuite.custhelp.com/app/answers/detail/a_id/100295
😃 1