Hi, my suitescript 2 is not saving shipping method...
# suitescript
p
Hi, my suitescript 2 is not saving shipping method for order my code is below:
Copy code
var salesOrder = record.create({
            type: record.Type.SALES_ORDER,
            isDynamic: true,
            defaultValues: Date.now().toString
        });

 salesOrder.setValue({ fieldId: 'shipcarrier', value: "nonups" });
 salesOrder.setValue({ fieldId: 'shipmethod', value: nonUpsMethodsList[data["shipping_method"]["#text"]] });
b
What is the raw value you are setting for the shipmethod
p
i have tried 4 and '4' and "4" nothing works
and 4 is value for a shipping method dropdown
n
Not sure that's right defaultValues: Date.now().toString
b
make sure you are setting the shipmethod after entity
the ship method is only settable after you set the entity field in the ui
p
@NElliott Date is working fine, its also create order
b
alternatively dont use dynamic mode
n
Not sure how that's working but OK. defaultValues is a name / value pair such: defaultValues: { entity: 87 }
b
defaultValues is an Object
most things in javascript are Objects
n
yeah and you say which field you're populating and the value. Sorry maybe a different conversation just puzzled what you are assigning Date.now() to???
p
Yes in my code i'm setting entity in the start
@NElliott trandate
n
interesting, I thought you'd have to do trandate: Date.now() 😉
b
my only other guess is that '4' is not a valid ship method for your customer
p
i have tried another one too.
b
make sure that whatever ship method has internal id 4 is selectable when you choose your customer in the ui
4 is honestly suspiciously low internal id
anything between internal id 2 and 4 are generally useless
p
i have tried 6134 and also it didn't worked
b
whats the value of
Copy code
salesOrder.getField({fieldId: 'shipmethod'}).getSelectOptions()
right before you set the ship method\
p
where in the UI?
n
Date of the sales order is set to current date as a default. That's why the defaultValue part is "seems to be working" when in actual it is not.
😂 1
👌 1
@NElliott
p
one thing more, i wasn't setting the value of "shippingcost" when when i tried to set it, it give error
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "USER_ERROR",
  "message": "Please choose a shipping method to account for the shipping cost.",
  "stack": [
    "anonymous(N/serverRecordService)",
    "createSalesOrder(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:433)",
    "getSalesOrderInfo(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:137)",
    "Apicall(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:831)"
  ],
  "cause": {
    "type": "internal error",
    "code": "USER_ERROR",
    "details": "Please choose a shipping method to account for the shipping cost.",
    "userEvent": "beforeload",
    "stackTrace": [
      "anonymous(N/serverRecordService)",
      "createSalesOrder(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:433)",
      "getSalesOrderInfo(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:137)",
      "Apicall(/SuiteScripts/Webhive/tj_afg_soap_getsalesOrderListRequest.js:831)"
    ],
    "notifyOff": false
  },
  "id": "",
  "notifyOff": false,
  "userFacing": false
}
n
@Php what does this returns: nonUpsMethodsList[data["shipping_method"]["#text"]] ?
p
The value of shipping method.
n
are you sure this is working?
p
it creates the order and set every value that i want it to set except, shipmethod and shipcost
n
Can you go to Create New Sales Order in the UI, select the Customer, select the Ship Carrier. Then open the console of the browser and type this: nlapiSetFieldValue('shipmethod', 4); and check if it sets the Ship Method field.
p
Yes it does gets selected.
but shipping cost fields changes from 0.00 to To be Calculated
n
Did you try selecting the entity field first in your code as well?
p
yes i did
and its selecting the customer correctly too
n
Select the entity first, and then select the ship carrier and ship method. Also, try without dynamic mode as well.
p
i have tried both static and dynamic ways but nothing works, i guess.
n
Save the sales order, load it again and set the shipping method.
p
you can see my method that i am using to create sales order.
n
Ok.
I have updated your code. Try that.
p
okay
still no shipping method
?