Hi, everyone. I'm going to add some line items whe...
# general
g
Hi, everyone. I'm going to add some line items when creating vendor bill automatically. I'm going to do this in pageInit() of ClietScript.
Copy code
curRec.selectNewLine({sublistId: "item"});
curRec.setCurrentSublistValue({sublistId: "item", fieldId: 'item', value: 174,  ignoreFieldChange: true});
curRec.setCurrentSublistValue({sublistId: "item", fieldId: 'location', value: 1,  ignoreFieldChange: true});
....
curRec.commitLine({sublistId: 'item'});
When I create a vendor bill, I can see the line fields are filled correctly, but it is not committed. I've tried to find out if there's other clientscript deployed, but there's no other scripts. What is the problem here? Thanks in advance
a
you need to save the record too, not just commit the line.
g
Thank you for your fast answer.
But I want to check the record before saving it. I just want to add line items on vendor bill create page. Is it impossible?
a
I'm probably not understanding. On the UI are you saying your script is correctly filling out the lines or is it filling out 1 line and stopping?
g
Just fill one line and stop. It doesn't commit at all So what I see on the UI is the last line item.
a
you might want to post your code, but I'm wondering if it's a problem with your loop over the lines.
g
I don't think so, I tried with one line, with no loop, but it didn't work again
a
When you say it didn't work with 1 line, what did it do exactly?
g
this is what I see when I create a vendor bill
it is not committed
a
yeah that's interesting, let me test it on my end
🙌 1
is your record in dynamic mode?
g
the currentRecord in pageInit is dynamic as default, isn't it?
a
Perhaps, but worth checking...I think
1
g
a
What if we set ignoreFieldChange to false?
My wild theory here is that because we are in dynamic mode, the fields need to be sourced in real time. We are explicitly telling it to ignore field changes, therefore no sourcing on the lines, which is why I'm thinking we don't see any of the other fields we would normally see there and why commit line isn't working
g
but if I click add button as soon as I open vendor bill create page, it is added successfully
I want to ignore some standard fields, such as rate. That's why I set igenoreFieldchange to true
a
playing with it now, sorry for the delay
g
I really appreciate your cooperation
b
setCurrentSublistValue is actually asynchronous, so your code is committing the line before sourcing is complete
forceSyncSourcing to make the sourcing synchronous
g
Thanks, I'll try
Unfortunately, it doesn't work, still same result
b
what does the code look like now
a
I got it to work with that code:
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

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

    function pageInit(context) {
        var curRec = currentRecord.get();        
        curRec.selectNewLine({ sublistId: 'item' });        
        curRec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: 8,
            ignoreFieldChange: false, 
            forceSyncSourcing: true
        });
        curRec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'location',
            value: 106,
            ignoreFieldChange: false, 
            forceSyncSourcing: true
        });
        // Commit the line
        curRec.commitLine({ sublistId: 'item' });
    }

    return {
        pageInit: pageInit
    };
});
g
ignoreFieldChange: false?
a
oh, right, one sec
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

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

    function pageInit(context) {
        var curRec = currentRecord.get();      
        curRec.selectNewLine({ sublistId: 'item' });       
        curRec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            value: 8,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });
        curRec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'amount',
            value: 10,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });
        curRec.setCurrentSublistValue({
            sublistId: 'item',
            fieldId: 'location',
            value: 106,
            ignoreFieldChange: true,
            forceSyncSourcing: true
        });
        // Commit the line
        curRec.commitLine({ sublistId: 'item' });
    }

    return {
        pageInit: pageInit
    };
});
I had to set the amt but that worked on my end
g
oh, I set
ignoreFieldChange: false,
forceSyncSourcing: true
It suddenly worked
a
credit goes to @battk, thank you for the suggestion!
g
thank you, @amoreng, @battk
❤️ 1
why can't I set igenoreFieldChange to true?
a
you should be able to
b
your ability to use igenoreFieldChange is dependent on the record and field
netsuite's internal code uses field changes, and ignoring them can cause unexpected behavior
g
I see, Thank you for your kind help👍