I want to view record type which is selected on entity column in journal sublist?

I create a custom field and deploy a script. Here is my script and don’t know whats wrong in it.

/**
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([‘N/ui/dialog’,’N/record’,’N/log’],

    function(dialog,record,log) {
        function fieldChanged(context) {
            var currentRecord = context.currentRecord;
            var sublistid = context.sublistId;
            if(fieldChanged.fieldId ==’entity’){
                
            var name = currentRecord.getCurrentSublistValue({
                sublistId: ‘line’,
                fieldId: ‘entity’
            });
            // dialog.alert({
            //     title:’name:’,
            //     message: name
            // })
          if(name==record.Type.EMPLOYEE){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Employee’
            });
            console.log(name)
          }
          if(name==record.Type.CUSTOMER){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Customer’
            });
          }
          if(name==record.Type.VENDOR){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Vendor’
            });
          }
         dialog.alert({
                title:’name:’,
               message: name
             })
        }
      }
        return {

            fieldChanged: fieldChanged 
        }
        
    });
    
    

 

Beginner Asked on October 27, 2020 in How To's.
Add Comment
1 Answer(s)

Maybe Im wrong, but I think you always have to use the pageInit function… Try to include it

/**
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define([‘N/ui/dialog’,’N/record’,’N/log’],

 

    function(dialog,record,log) {

function pageInit(context) {

//nothing to do

}

        function fieldChanged(context) {
            var currentRecord = context.currentRecord;
            var sublistid = context.sublistId;
            if(fieldChanged.fieldId ==’entity’){
            var name = currentRecord.getCurrentSublistValue({
                sublistId: ‘line’,
                fieldId: ‘entity’
            });
            // dialog.alert({
            //     title:’name:’,
            //     message: name
            // })
          if(name==record.Type.EMPLOYEE){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Employee’
            });
            console.log(name)
          }
          if(name==record.Type.CUSTOMER){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Customer’
            });
          }
          if(name==record.Type.VENDOR){
            currentRecord.setCurrentSublistValue({
                sublistId:’line’,
                fieldId:’custcol_ks_recordtype’,
                value:’Vendor’
            });
          }
         dialog.alert({
                title:’name:’,
               message: name
             })
        }
      }
        return {
            pageInit: pageInit,
            fieldChanged: fieldChanged
        }
    });
Rookie Answered on October 29, 2020.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor