Does anyone knows what is the sublist ID and the f...
# suitescript
j
Does anyone knows what is the sublist ID and the field IDs I can use to populate the fields such as 'From Quantity'? I tried finding the fields in the records browser but under itempricing subrecord I can't find the fields that it uses.
b
load the record in the suitescript debugger to see what the record looks like
r
j
So now I managed to find the fields but it seems I can't set a field value for them. I followed the guide given to me by battk earlier but it just returns me no values at all when I tried to set values with the following code.
Copy code
var subrec = loadrec.getSublistSubrecord({
            sublistId: 'item',
            line: 0,	
    		fieldId: 'itempricing'
        });
   subrec.insertLine({
            sublistId: 'discount',
            line: 1
        });  
 subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'memo',
            line: 1,
            value: 'OneTest'
        });
   }
I am also using suite answer number 78787 as a reference but I am stuck. Any help will be appreciated.
b
what errors are you getting?
j
I actually doesn't have any errors whenever I execute it. It just doesn't fill in any values at all
It just returns the same value and not even inserting a new line
b
you should at least get an error about missing the mandatory fields
what does all your code look like
j
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope Public
 */
define(['N/record'],
  function(record){
  function myAfterSubmit(scriptContext){
var loadrec = record.load({
            type: record.Type.PURCHASE_CONTRACT,
	        id: 35573,
            isDynamic: false
        });

  var subrec = loadrec.getSublistSubrecord({
            sublistId: 'item',
            line: 0,	
    		fieldId: 'itempricing'
        });
   subrec.insertLine({
            sublistId: 'discount',
            line: 1
        });  
 subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'memo',
            line: 1,
            value: 'One'
        });
   }	
        
  return {
        afterSubmit: myAfterSubmit
    };
});
It's kind of weird because I am not getting those errors even from the start.
I also tried using
selectLine
instead of
insertLine
but I am getting "Cannot find function selectLine in object standard subrecord."
b
save the record
j
I am already saving it and the screenshot earlier was the result after
b
the code you shared is working as designed
it does nothing
j
So how should I modify it if I want to fill in or change fields under Additional Pricing?
b
learn how the N/record module works
you will not get very far trying to do more advanced stuff without leaning the basics
j
Okay will do! Thanks!
Okay so I managed to make it work with this script:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope Public
 */
define(['N/record'],
  function(record){
  function myAfterSubmit(scriptContext){
    var recordType = record.Type.PURCHASE_CONTRACT;
    var recordID = 35573;
    var isDynamic = false;
    
var loadrec = record.load({
            type: recordType,
	        id: recordID,
            isDynamic: isDynamic,
        });
    
    loadrec.getSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: 463,
      		line: 0
        });
    loadrec.setSublistValue({
            sublistId: 'item',
            fieldId: 'rate',
            value: '33522',
      		line: 0
        });
  var subrec = loadrec.getSublistSubrecord({
            sublistId: 'item',
            line: 0,	
    		fieldId: 'itempricing'
        });
    
   subrec.insertLine({
            sublistId: 'discount',
            line: 0
        });  
    
    subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'fromquantity',
            line: 0,
      		value: 17
        });
    subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'percent',
            line: 0,
            value: '10'
        });
    subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'quantityordered',
            line: 0,
            value: '12'
        });
    subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'rate',
            line: 0,
            value: '255325'
        });
 subrec.setSublistValue({	
            sublistId: 'discount',
            fieldId: 'memo',
            line: 0,
            value: 'OneTwoThree'
        });
        var recordsave = loadrec.save();
    }	
  return {
        afterSubmit: myAfterSubmit
    };
    
});
But now when I am trying to create a record it shows me a new error
message has been deleted
/** *@NApiVersion 2.x *@NScriptType ScheduledScript */ define(['N/search', 'N/record', 'N/runtime', 'N/format', 'N/file'], function (search, record, runtime, format, file) { function main() { try{ var oldId = 0; var purchasecontract = record.create({type: record.Type.PURCHASE_CONTRACT}); // システム管理ID purchasecontract.setValue({ fieldId: 'externalId', value: oldId, }); // 仕入先 purchasecontract.setValue({ fieldId: 'entity', value: 2229, }); // 子会社 「プレミアアンチエイジング株式会社」固定 purchasecontract.setValue({ fieldId: 'subsidiary', value: '1', }); // 次に基づく有効性 purchasecontract.setValue({ fieldId: 'effectivitybasedon', value: 'ORDERDATE', }); // 最高金額 purchasecontract.setValue({ fieldId: 'maximumamount', value: 100, }); // 子会社 purchasecontract.setValue({ fieldId: 'subsidiary', value: '1', }); // 契約開始日 purchasecontract.setValue({ fieldId: 'startdate', value: format.parse({ value: '2021/07/09', type: format.Type.DATE }), }); // 日付 purchasecontract.setValue({ fieldId: 'trandate', value: format.parse({ value: '2021/07/09', type: format.Type.DATE }), }); purchasecontract.setSublistValue(populateSublistField('item', 'item', 0, 460)); purchasecontract.setSublistValue(populateSublistField('item', 'department', 0,'33')); purchasecontract.setSublistValue(populateSublistField('item', 'rate', 0,'200')); var subrec = purchasecontract.getSublistSubrecord({ sublistId: 'item', line: 0, fieldId: 'itempricing' }); subrec.insertLine({ sublistId: 'discount', line: 0 }); subrec.setSublistValue(populateSublistField('discount', 'fromquantity', 0, 17)); subrec.setSublistValue(populateSublistField('discount', 'percent', 0, '10')); subrec.setSublistValue(populateSublistField('discount', 'quantityordered', 0, '12')); subrec.setSublistValue(populateSublistField('discount', 'rate', 0, '200')); subrec.setSublistValue(populateSublistField('discount', 'memo', 0, 'OneTwoThree')); var savedId = purchasecontract.save(); l(JSON.stringify(purchasecontract)); l('update_purchasecontract_success>>>'); } catch (e) { l('>> update_purchasecontract!!!! ' + e); } function populateSublistField(sublistId, fieldId, line, fieldValue) { return { 'sublistId': sublistId, 'fieldId': fieldId, 'line': line, 'value': fieldValue } } function l(str) { log.debug({ title: str, details: str }); } } return { execute: main }; });
And right now I am using the script. I am just doing the same method as the first but it seems I can't make it work again. Any hints?
b
sounds like it doesnt think you properly set the rate on the item sublist
try using dynamic mode