Hi All, I Can Create a Cash Sale By adding the acc...
# suitescript
g
Hi All, I Can Create a Cash Sale By adding the account attached below, the same thing if i do it from suitscript Restlet api it returns me
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "USER_ERROR",
  "message": "Please enter a value for Account.",
  "id": "",
  "stack": [
    "anonymous(N/serverRecordService)",
    "_post(/SuiteScripts/RestLet_Crude_Operation.js:143)"
  ],
  "cause": {
    "type": "internal error",
    "code": "USER_ERROR",
    "details": "Please enter a value for Account.",
    "userEvent": null,
    "stackTrace": [
      "anonymous(N/serverRecordService)",
      "_post(/SuiteScripts/RestLet_Crude_Operation.js:143)"
    ],
    "notifyOff": false
  },
  "notifyOff": false,
  "userFacing": false
}
I Tried to add it in the code same order as i do it in the Ui, but it won't work This is my ResetLet Api Code
Copy code
function _post(context) {
    doValidation([context.recordtype], ["recordtype"], "POST");
    try {
      var rec = record.create({ type: context.recordtype, isDynamic: true });
      for (var fldName in context) {
        if (context.hasOwnProperty(fldName)) {
          if (fldName !== "recordtype" && fldName !== "sublists") {
            var fieldObj = rec.getField({ fieldId: fldName });
            log.debug({
              title: "Post Request Processed",
              details: { fieldObj: fieldObj, fldName: fldName,value:context[fldName] },
            });
            if (fieldObj && fieldObj.type === "date") {
              rec.setValue(fldName, new Date(context[fldName]));
            } else {
              rec.setValue(fldName, context[fldName]);
            }
          }
        }
      }
      if (context.sublists) {
        var sublists = context.sublists;
        for (var sublistsId in sublists) {
          var records = sublists[sublistsId].records;
          for (var i = 0; i < records.length; i++) {
            rec.selectNewLine({ sublistId: sublistsId });
            for (var sublistsFieldName in records[i]) {
              var sublistFieldObj = rec.getSublistField({
                sublistId: sublistsId,
                fieldId: sublistsFieldName,
                line: i,
              });
              if (sublistsFieldName === "contact") {
                var contactRecord = record.load({
                  type: record.Type.CONTACT,
                  id: records[i][sublistsFieldName],
                });
                rec.setCurrentSublistValue({
                  sublistId: sublistsId,
                  fieldId: sublistsFieldName,
                  value: contactRecord.id,
                });
              } else if (sublistFieldObj && sublistFieldObj.type === "date") {
                rec.setCurrentSublistValue({
                  sublistId: sublistsId,
                  fieldId: sublistsFieldName,
                  value: new Date(records[i][sublistsFieldName]),
                });
              } else {
                rec.setCurrentSublistValue({
                  sublistId: sublistsId,
                  fieldId: sublistsFieldName,
                  value: records[i][sublistsFieldName],
                });
              }
            }
            rec.commitLine({ sublistId: sublistsId });
          }
        }
      }
      var recordId = rec.save();
      return JSON.stringify(recordId);
    } catch (err) {
      return JSON.stringify(err);
    }
  }
and this is my request data
Copy code
const data = {
      recordtype: "cashsale",
      entity: entity,
      undepfunds: "F",
      account: "717",
      opportunity: opportunity,
      salesrep: "8",
      department: "4",
      memo: updatedMemo,
      cseg_property: property,
      otherrefnum: check,
      trandate:date,
      billingaddress_text: billingaddress,
      custbody_ncrr_opp_orig_portal_num: ApplicationTitle,
      custbody_ncrr_opp_hntb_num: HNTBFileNumber,
      custbodyportal_link: `${link}`,
      sublists:{
        item: {
          records: [
            {
              item: item1,
              cseg_property: property,
              description: updatedMemo,
              line: line1,
              department: 4,
            },
            {
              item: item2,
              cseg_property: property,
              description: updatedMemo,
              line: line2,
              department: 4,
            }
         ]
        },
      }
    };
is There anything i am missing ?
b
probably want to start logging your record at the end to see if the account is actually set
if it is, you may want to make sure there are no user event scripts or workflows messing with payment information