SuiteScript2.0 - 将机会转换为销售订单未正确设置送货地址

SuiteScript2.0 - Transforming Opportunity to Sales Order does not set Shipping Address Correctly

我正在尝试通过单击按钮自动创建潜在客户、商机和销售订单。下面的代码是我如何在 suilet 上实现的。除了销售订单上的送货地址外,一切都已创建并完美设置。由于某种原因,销售订单的送货地址被设置为自定义并且只输入州和邮政编码。我很确定我没有为销售订单创建地址,我觉得它应该像账单地址一样默认为客户的默认送货地址。我已经给出了 data.saleorder 数据。

function submitdata(data){
    var leadid = createLead(data);
    var opportunityid = createOpportunity(data, leadid);
    var salesorderid;
    if(data.salesorder) {
        salesorderid = transformRecordAndSetNewValues({
            from : {
                type : record.Type.OPPORTUNITY, 
                id : opportunityid
            },
            to : {
                type : record.Type.SALES_ORDER
            },
            values : data.salesorder,
            ignoreMandatoryFields : false,
        });
    }
    return {
        leadid,
        opportunityid,
        salesorderid,
        success : true
    }
}

function transformRecordAndSetNewValues(data){
    var objRecord = record.transform({
        fromType : data.from.type,
        fromId : data.from.id,
        toType : data.to.type,
        isDynamic : true,
        defaultValues : {
            customform : Number(data.values.customform)
        }
    });
    setRecordValues(objRecord, data.values);
    var recId = objRecord.save({
        ignoreMandatoryFields : data.ignoreMandatoryFields
    });
    setRecordForm({
        recordid : recId,
        form : data.values.customform,
        type : data.to.type
    });
    return recId;
}

function setRecordValues(objRecord, values)
{
    //Loop Fields And Add Values
    for(var key in values){
        log.debug(key, values[key])
        if(key == "shippingaddress" || key === "billingaddress"){
            createAddress(objRecord, key, values)
            continue;
        }
        //if(key === "type") continue;
        var value = values[key];
        value = testForBooleanAndConvertToBoolean(value)
        value = testForDateAndConvertToDate(value)
        objRecord.setValue({
            fieldId : key,
            value : value
        })
    }
}

{
    "lines": [
        {
            "item": {
                "id": "1234",
                "sku": "ANSKU",
                "pricelevels": {
                    "1": "118.09091",
                    "6": "82.66364",
                    "7": "47.23636",
                    "9": "112.19",
                    "10": "106.28",
                    "11": "100.38",
                    "12": "94.47"
                },
                "taxcode": {
                    "text": "GST",
                    "value": "7"
                },
                "taxrate": "10.00",
                "displayname": "An Item Descripton",
                "description": "An Item Descripton",
                "type": {
                    "text": "Inventory Item",
                    "value": "InvtPart"
                },
                "model": ""
            },
            "quantity": 1,
            "pricelevel": {
                "value": "1",
                "text": "BASE PRICE"
            },
            "rate": "118.09091",
            "amount": "118.09",
            "taxcode": "GST",
            "taxrate1": "10.00",
            "tax1amt": "11.81",
            "grossamount": "129.90"
        }
    ],
    "customform": 101,
    "formtype": true,
    "department": "7",
    "location": "1",
    "terms": "7",
    "timeslot": "2021-01-28",
    "shipmethod": "1234",
    "id": "123456"
}

转换为销售订单时,设置'entity'字段。