0
votes

I've created a client script (field change) on a task record. The Sublist is a custom child record. I want that if a bodyfield checkbox is set to true -> change all sublist line items... In theory a " Mark all / select" all checkbox for the sublist.

The script is working for at least 1 line... If I use selectline "i" it will work with the LAST line of the sublist -> if I start with "0" it changes the value on the first line...

How can I solve this?

/**
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */

define(['N/error', 'N/currentRecord'],
    function(error) {

        function fieldChanged(context) {

            var currentRecord = context.currentRecord;

            var subList = currentRecord.getSublist({
            sublistId: 'recmachcustrecord250'});

            var numLines = currentRecord.getLineCount({
            sublistId: 'recmachcustrecord250'});

          var currIndex = currentRecord.getCurrentSublistIndex({
            sublistId: 'recmachcustrecord250'});


                for (var i = 0; i < numLines; i++)  {

                var checkbox = currentRecord.getValue({
                fieldId: 'custevent28'});

                  currentRecord.selectLine({
                    sublistId: 'recmachcustrecord250',
                        line: 0});

        if(context.fieldId == 'custevent28'){
                if (checkbox == true) {
            currentRecord.setCurrentSublistValue({
            sublistId: 'recmachcustrecord250',
            fieldId: 'custrecord265',
            line: i,
            value: true,
            forceSyncSourcing:true
            });
        } else {
            currentRecord.setCurrentSublistValue({
            sublistId: 'recmachcustrecord250',
            fieldId: 'custrecord265',
            line: i,
            value: false,
            forceSyncSourcing:true
            });

            currentRecord.commitLine({
            sublistId: 'recmachcustrecord250'});
        }
            }
            }


        }

        return {
            fieldChanged: fieldChanged
        };
    });
1

1 Answers

0
votes

Found it... set CurrentSublistValue is without "line" & with ignoreFieldchange...

if(context.fieldId == 'custevent28'){
                if (checkbox == true) {
            currentRecord.setCurrentSublistValue({
            sublistId: 'recmachcustrecord250',
            fieldId: 'custrecord265',
           // line: i,
            value: currentRecord.getValue({
            fieldId: 'custevent28'}),
            ignoreFieldChange: true
            });
            currentRecord.commitLine({
            sublistId: 'recmachcustrecord250'});
        } else {
            currentRecord.setCurrentSublistValue({
            sublistId: 'recmachcustrecord250',
            fieldId: 'custrecord265',
          //  line: i,
            value: currentRecord.getValue({
            fieldId: 'custevent28'}),
            ignoreFieldChange: true
            });