Hi all, odd quirk in SuiteScript 2.1 here. I get t...
# suitescript
g
Hi all, odd quirk in SuiteScript 2.1 here. I get the following error in a Purchase Order - User Event script when purchase orders are saved by a Map/Reduce script. Error does not occur in the UI.
Invalid API usage. You must use getSublistValue to return the value set with setSublistValue.
But I'm not using setSublistValue...
Copy code
function beforeSubmit(context) {
    try {

      // For each expense line, if custcoll_gnt_comm_rqst has a value, copy it to cseg_comseg
      for (var i = 0; i < context.newRecord.getLineCount({ sublistId: 'expense' }); i++) {
        var commNo = context.newRecord.getSublistText({ sublistId: 'expense', fieldId: 'custcoll_gnt_comm_rqst', line: i });

        if (commNo) {
          context.newRecord.setSublistText({ sublistId: 'expense', fieldId: 'cseg_comseg', text: commNo, line: i });
        }
      }
    } catch (e) {
      log.error({
        title: 'Error in beforeSubmit',
        details: e
      });
    }
  }
I think I figured out the issue just by posting this, I'll post it anyway though and see if the Map/Reduce is using setSublistValue. The purpose of this script is to copy the value of a deprecated custom record to the custom segment that replaced it so that legacy automations can keep working while we migrate to the new segment.
Yup, in the map/reduce:
Copy code
newPurchaseOrderObj.setCurrentSublistValue({
						sublistId: 'item',
						fieldId: 'custcoll_gnt_comm_rqst',
						value: commitmentRequestObj.values.custrecord_gnt_prchs_cmmtmnt_req_prnt_lk.value
					});
Therefore the solution is to use search.lookupfields to get the text value of the custom record field, or do it afterSubmit when the field will behave like normal again.
c
I often see issues where setSublistText doesn't give me anything.
Despite using it as per the docs.
Are you claiming setSublistText worked in the UE but not the MR or are you sating it worked after using lookUpFields to get the text instead of getText?
g
it didn't like getSublistText when the field had been set during the same save by the same map/reduce's setCurrentSublist Value
c
If the same script sets and reads the value (in that order); can’t you just use the same value from the set?
g
No it's a user event triggered by the map/reduce
not the same script