Hi All! This is my post request of a restlet funct...
# suitescript
g
Hi All! This is my post request of a restlet function
Copy code
function _post(context) {
    try {
      var rec = record.create({ type: context.recordtype, isDynamic: true });
      for (var fldName in context) {
        if (context.hasOwnProperty(fldName)) {
          if (fldName !== "recordtype" && fldName !== "sublists") {
            if (fldName.indexOf("date") !== -1) {
              rec.setValue(fldName, new Date(context[fldName]));
            } else {
              rec.setValue(fldName, context[fldName]);
            }
          }
        }
      }
      var recordId = rec.save();
      return JSON.stringify(recordId);
    } catch (err) {
      return JSON.stringify(err);
    }
  }
And this is my object which i am sending data
Copy code
const data = {
      recordtype: "opportunity",
      entity: entity,
      custbodyreceiveddate:applicationData.createdOn,
      entitystatus: "10",
      salesrep: 8,
      custbodyactionstatus: 4,
      department: 4,
      cseg_property: property,
      custbodytransactionunit: unit,
      custbody_ncrr_opp_orig_portal_num: applicationTitle,
      custbody_ncrr_opp_hntb_num: HNTBFileNumber,
      custbodyportal_link:link,
      externalid: `${applicationID}_OPPORTUNITY`,
    };
here custbodyreceiveddate is a date field so i am converting it to Date Object in the Reselet Function like this
Copy code
rec.setValue(fldName, new Date(context[fldName]));
But the Date Field is not adding and it doesnt give any error as well The Received Date is Empty any solution for this?
e
What's the value in
applicationData.createdOn
?
g
Its a Date Object Directly from Database mongoDB
w
you might want to create a date parser function to create a JavaScript date object for that mongoDb date object. also may I suggest doing this too: var fieldObj = rec.getField({fieldId: fieldName}); if (fieldObj.type === ‘date’) ^ this way you don’t rely on your fieldId to have a ‘date’ on its name and your code is much flexible for additional date fields.
g
Thanks alot @wbermudo 😊