Hi. I am trying to update the department field on ...
# suitescript
b
Hi. I am trying to update the department field on an inventory adjustment record using suitescript. I am getting the value into a variable in my script - both the internal id of the department or the department name itself. I can then put the value in a text field, but using the same logic, nothing appears in the department field. This needs to trigger when the user is entering data onto the transaction form. What am I doing wrong? This is the function from my client script.
Copy code
function fieldChanged(context){
        let currentRecord = context.currentRecord;
        let mrp = currentRecord.getValue({ fieldId: 'custbody_person' });
        let mrpdept = search.lookupFields({
            type: 'employee', id: mrp, columns: ['department']
          });
        let mrpdeptText = mrpdept.department[0].text; // THIS RETURNS TEXT VALUE OF DEPARTMENT FIELD
        let mrpdept2 = mrpdept.department[0].value;   // THIS RETURNS INTERNAL ID OF DEPARTMENT FIELD
        currentRecord.setValue({fieldId : 'custbody_adjust_reason', value :mrpdeptText, ignoreFieldChange: true});           // THIS WORKS
        currentRecord.setValue({fieldId : 'memo', value :mrpdept2, ignoreFieldChange: true});                                // THIS WORKS 
        currentRecord.setValue({fieldId : 'department', value :mrpdept2, ignoreFieldChange: true,forceSyncSourcing: true});  // THIS DOESN'T WORK
    }
j
Have you tried to follow the exact same test steps in the UI? For example, some classifications do not load if the subsidiary is not selected
😀 1
b
Thanks Jorge, I knew I was doing something stupid as it's the end of a long day. Whilst I was testing I was not entering the subsidiary. Now after doing that and a couple of other tweaks everything is working 🙂
🎉 1
🙌 1