Does anyone faced infinite loop when you use valid...
# suitescript
b
Does anyone faced infinite loop when you use validateField in client script please?
c
Are you editing the field that's being validated? Consider setting a flag of some kind in the browser window to provide an exit
b
@Clay Roper could you elaborate a little more please?
c
@Boris Yasen I'd be happy to; it would be best to do so with the context of your code. Can you add a snippet here with the text of your function as it stands?
b
It's just simple as this
Copy code
if(scriptContext.fieldId == "custpage_end_date"){
                        dialog.alert({
                            title: 'You can\'t edit End date',
                            message: 'It\'s already started'
                        });
                        return false;
}
return true;
Actually it's a sublist column field, not the header field
so I don't want user to be able to edit that specific line column
so if he is trying to edit it, I'm throwing an error
a
are you wanting to prevent them doing that based on something else they already did in the client context?
c
@Boris Yasen Have you tried disabling the field?
b
the issue is only for some lines
not all sublist
👍 1
Yes @Anthony OConnor
c
@Boris Yasen You can disable the field dynamically in lineInit based on your business logic
b
could you send me the code snippet for that please?
I didn't know it's possible
So let's say sublist has 3 rows and 3 columns. I want to disable 1st row 2nd column and 3rd row 3rd column?
e
What are the criteria for rows? Always disable the first or when a condition is met?
s
an easy infinite loop solution is something like
_.debounce()
c
Try something like this.
@Boris Yasen You would manage the disabling each time a line is selected, thus the usage of lineInit
b
Thank you
c
@Boris Yasen One thing to note that I'm dealing with at the moment: Purchase Order item lines can fight your efforts to manage the fields, maybe only if you have the Purchase Contracts feature enabled.
b
Can I disable the column based on same row value in lineInit?
c
You mean select the value of a field on the line being selected then disable the field according to that value or logic derived from that value? You should be able to do so with
rec.getCurrentSublistValue()
b
Sorry but it changed all rows, not only one certain row
c
@Boris Yasen Can you share your code?
b
Copy code
function lineInit(scriptContext){
        if(scriptContext.currentRecord.getValue('custpage_hidden_is_fully_loaded') && scriptContext.currentRecord.getLineCount({sublistId: 'custpage_lines'}) > 0){
            if(scriptContext.sublistId == "custpage_lines"){
                let LineStatus = scriptContext.currentRecord.getCurrentSublistValue({
                    sublistId: 'custpage_lines',
                    fieldId: 'custpage_line_status'
                });

                console.log('lineInit', LineStatus);
                    
                if(LineStatus == 1){
                    const { currentRecord: rec, sublistId } = scriptContext;
                    const line = rec.getCurrentSublistIndex({ sublistId });
                    console.log('line');
                    rec.getSublistField({
                      fieldId: "custpage_line_end_date",
                      sublistId,
                      line
                    }).isDisabled = true;
                }else{
                    const { currentRecord: rec, sublistId } = scriptContext;
                    const line = rec.getCurrentSublistIndex({ sublistId });
                    console.log('line');
                    rec.getSublistField({
                      fieldId: "custpage_line_end_date",
                      sublistId,
                      line
                    }).isDisabled = false;
                }
            }
        }
    }
c
@Boris Yasen Are you saying that every line you select has this field disabled?
b
yes
c
Even when LineStatus !== 1?
b
yes
c
Can you console.log from inside both branches of the if/else?
b
I tried and it returned correct value
2 or 1
but always disabled
c
If you log from both branches of the if/else, we can ensure it's reaching the right branch
s
Sorry I'm not entirely following along, but AFAIK you can only disable columns - you can't disable individual cells.
c
@Shawn Talbert Correct, but the column is only represented on a line by line basis, so you can manage it when the line is selected.
@Boris Yasen I've deployed this to Sales Orders and am seeing it function as expected -- lines with a quantity higher than 10 when selected disable the description field; otherwise, it's enabled.
@Shawn Talbert See the snippet above. @Boris Yasen this method of disabling fields may not work for all field types; in those cases, you can perform a hack with jQuery
s
That does disable it for the entire column right? You're just saying that doesn't matter because the user is focused on a single line at a time?
c
I don't know that we can even really speak about it being disabled for the whole column when the only way to interact with a given field is one line at a time. It might be different if I was addressing the column, but I haven't worked with Columns in that way to be able to say.