Skip to main content

I have been struggling with this for a while here.


FYI beginner coder here



I have 3 single select fields (Curtain Status, Rail Status, Vert Status). All three of these options have the following selections: “Adjustment”, “Waiting Install”," Adjustment", “On Hold”, “Canceled”, “Finished”



There are three checkboxes for each of the single select fields: REDO - C, REDO - R, REDO - V"



The end goal of this script is that when





  1. REDO-C or REDO -R, or - REDO V is checked.


  2. the check boxes are automatically unchecked




  3. if Curtain Status or Rail Status or Vert Status is sBlank, “Adjustment”, “Waiting Install”, “Adjustment”, “On Hold”, “Canceled”, “Finished”]:


    then Curtain Status, Rail Status, Vert Status will be left un changed.


  4. if Curtain Status, Rail Status, Vert Status is anything else: Their value will be set to “Pending”




I got most it all to work except when the single field is blank. I’m getting a :TypeError: Cannot read property ‘name’ of null at main on line.



This error is generated when, for example, statusc’s getCellvalue is set to read .name and the single select is blank.



I was first able to get around this by including null in my if statement:



if (redoc == true && statusc !== null )



However, when testing the array “state” against “statusc” I need to include the .names property in order for it to work:





if (state.indexOf(statusc.name) !== -1) {

console.log("Leave Current Status");

}



I cant figure out how to get this to work without getting the null-error.



FYI: I still need to input the “state” variable in the if statement below, havent gotten there yet since im stuck 😦



Some help on this would be greatly appreciated!



thanks in advance.



let worktable = base.getTable("Work Orders")

let worktablerecords = await worktable.selectRecordsAsync();



var check = input.config();







//List of checkboxes

let redoc = worktablerecords.getRecord(check.recordId).getCellValue("REDO - C");

let redor = worktablerecords.getRecord(check.recordId).getCellValue("REDO - R");

let redov = worktablerecords.getRecord(check.recordId).getCellValue("REDO - V");

//List of Status

let statusc = worktablerecords.getRecord(check.recordId).getCellValue("Curtain Status");

let statusr = worktablerecords.getRecord(check.recordId).getCellValue("Rail Status");

let statusv = worktablerecords.getRecord(check.recordId).getCellValue("Vert Status");



//IF the variable state is any value in this array, then "Curtain Status" will remain unchanged

var state = t"Adjustment","Waiting Install","Adjustment","On Hold","Canceled","Finished",null];







//FOR TESTING

if (state.indexOf(statusc.name) !== -1) {

console.log("Leave Current Status");

}

console.log(statusc.name)



//console.log(state);



//FOR TESTING

if (statusc == state) {

console.log("Leave")

} else {

console.log("1111")

};



console.log(state.includes(statusc.name));





if (redoc == true && statusc !== null ) {

await worktable.updateRecordAsync(check.recordId, {

"REDO - C": false,

});

await worktable.updateRecordAsync(check.recordId, {

"Curtain Status": {name: "Pending"}

});

} else if (redoc == true && statusc == null ){

await worktable.updateRecordAsync(check.recordId, {

"REDO - C": false,

})

} else {};



// if (redor == true && statusr !==null ) {

// await worktable.updateRecordAsync(check.recordId, {

// "REDO - R": false,

// });

// await worktable.updateRecordAsync(check.recordId, {

// "Rail Status": {name: "Pending"}

// });

// } else if (redor == true && statusr == null ){

// await worktable.updateRecordAsync(check.recordId, {

// "REDO - R": false,

// })

// } else {};



// if (redov == true && statusv !== null ) {

// await worktable.updateRecordAsync(check.recordId, {

// "REDO - V": false,

// });

// await worktable.updateRecordAsync(check.recordId, {

// "Vert Status": {name: "Pending"}

// });

// } else if (redov == true && statusv == null ){

// await worktable.updateRecordAsync(check.recordId, {

// "REDO - V": false,

// })

// } else {};



no one can help out with this???


Reply