Как обновить заказ на продажу, используя форму сулета? - PullRequest
0 голосов
/ 18 апреля 2019

Я создал пользовательскую форму, которая похожа на SalesOrder в Netsuite.Я хотел бы обновить продавец с помощью этой пользовательской формы.

Первая часть: я создал пользовательскую форму с настраиваемым полем под названием «номер заказа на продажу» и кнопкой «Отправить».Когда пользователь вводит в форму существующий номер заказа на продажу и отправляет форму, он отображает все поля, связанные с продавцом.Я успешно завершил первую часть.Я создал пакет и загрузил заказ на продажу и заполнил поля элементов и уровня тела в пользовательской форме.

Вторая часть: когда пользователь добавляет элементы или обновляет существующий элемент в пользовательской форме и отправляет форму cusotm, ему необходимобыть обновленным в записи заказа на продажу.Я не успешен со второй частью.Я попытался создать клиентский скрипт и связал его с чемоданом.Теперь я не могу обновить поле пользовательской формы и информацию о товарах в заказе на продажу.Пожалуйста, найдите следующий код

// Suitlet:

function onRequest(context) {
    try {
        if (context.request.method === 'GET') {
            showForm(context);
        } else {
            showResults(context);
        }
    } catch (e) {
        log.error('onRequest_', 'ERROR : ' + e.message);

        var errObj = error.create({
            name : 'SL ERROR',
            message : e.message,
            notifyOff : true
        });
        log.debug("errObj: ",errObj);
        throw 'ERROR: ' + e.message;
    }
}
function showForm(context) {

    var form = ui.createForm({
        title : 'Update SO'
    });

    var req = context.request;

    var soSearch = form.addField({
        id : 'so_search',
        type : ui.FieldType.TEXT,
        label : 'SO# SEARCH'
    });
    soSearch.isMandatory = true;

    form.addSubmitButton({
        label : 'Search'
    });

    context.response.writePage(form);
 function showResults(context) {

    var form = ui.createForm({
        title : 'Updating SO#' + context.request.parameters['so_search']
    });
   var req = context.request;
   log.debug("req: ",req);
    form.clientScriptFileId = 29546;
    log.debug("form.clientScriptFileId: ",form.clientScriptFileId);
 var soSearch = form.addField({
        id : 'so_search',
        type : ui.FieldType.TEXT,
        label : 'SO# Search'
    });
    soSearch.isMandatory = true;
    soSearch.defaultValue = context.request.parameters['so_search'];

    form.addSubmitButton({
        label : 'Search'
    });

    // Button to update the Purchase Order
    form.addButton({
        id : 'custpage_updaterecord',
        label : 'Update Record',
        functionName: 'updateRecord'
    });
 var itemSublist = form.addSublist({
        id : 'custpage_item',
        type : ui.SublistType.INLINEEDITOR,
        label : 'Item(s)'
    });

    // Item
    var itemCol = itemSublist.addField({
        id : 'custpage_item_item',
        label : 'Item',
        type : ui.FieldType.SELECT,
        source : 'item'
    }).updateDisplayType({
        displayType : ui.FieldDisplayType.ENTRY
    });

    // Description
    var descCol = itemSublist.addField({
        id : 'custpage_item_desc',
        label : 'Description',
        type : ui.FieldType.TEXT
    });

    // Price
    var priceCol = itemSublist.addField({
        id : 'custpage_item_price',
        label : 'Price',
        type : ui.FieldType.CURRENCY
    }).updateDisplayType({
        displayType : ui.FieldDisplayType.ENTRY
    });
s.create({
        type: s.Type.SALES_ORDER,
        columns: [
            'internalid'
        ],
        filters: [
            s.createFilter({
                name: "tranid",
                operator: s.Operator.IS,
                values: context.request.parameters['so_search']//"SO" + context.request.parameters['so_search']
            }),
            s.createFilter({
                name: "mainline",
                operator: s.Operator.IS,
                values: true
            })
        ]
    }).run().each(function(result) {
        // There should be no more than 1 result
        if (result.id) {
            // Load the SO
             log.debug("result.id: ",result.id);
            var rec = record.load({
                type: record.Type.SALES_ORDER,
                id: result.id
            });
            log.debug("rec: ",rec);
            // Loop through the items sublist to create our list
            var lineCount = rec.getLineCount({
                sublistId: 'item'
            });


            for (i = 0; i < lineCount; i++) {
                // Get then set the Item
                var item = rec.getSublistValue({
                    sublistId: 'item',
                    fieldId: 'item',
                    line: i
                });
                log.debug("item: ",item);
                itemSublist.setSublistValue({
                    id: 'custpage_item_item',
                    line: i,
                    value: item
                });

                // Get then set the Description
                var desc = rec.getSublistValue({
                    sublistId: 'item',
                    fieldId: 'description',
                    line: i
                });
                log.debug("desc: ",desc);
                if (desc) {
                    itemSublist.setSublistValue({
                        id: 'custpage_item_desc',
                        line: i,
                        value: desc
                    });
                }

                // Get then set the salesorder amount
                var price = rec.getSublistValue({
                    sublistId: 'item',
                    fieldId: 'amount',
                    line: i
                });

                if (price) {
                    itemSublist.setSublistValue({
                        id: 'custpage_item_price',
                        line: i,
                        value: price
                    });
                }
 }

            return false;
        }
        });

    context.response.writePage(form);
}
return {
    onRequest: onRequest
};

});

// Сценарий клиента:

function updateRecord() {
     try{
 var currentRecObj = currentRecord.get();
 var cust_clalimnumber = currentRecObj.getValue({fieldId:'so_search'});
 var lineCount = currentRecObj.getLineCount({
          sublistId: 'custpage_item'
      });
      for(var i=0;i<lineCount;i++){
      var cust_itemName = currentRecObj.getSublistValue({
          sublistId: 'custpage_item',
          fieldId: 'custpage_item_item',
          line: i
      });
      alert("cust_itemName: "+cust_itemName);
      var cust_itemDesc = currentRecObj.getSublistValue({
          sublistId: 'custpage_item',
          fieldId: 'custpage_item_desc',
          line: i
      });
      alert("cust_itemDesc: "+cust_itemDesc);
      var cust_itemAmount = currentRecObj.getSublistValue({
          sublistId: 'custpage_item',
          fieldId: 'custpage_item_price',
          line: i
      });
      alert("cust_itemAmount: "+cust_itemAmount);
    var salesorderSearchObj = search.create({
           type: "salesorder",
           filters:
           [
              ["type","anyof","SalesOrd"], 
              "AND", 
              ["mainline","is","T"], 
              "AND", 
              ["numbertext","is",cust_clalimnumber]
           ],
           columns:
           [
               search.createColumn({name: "internalid", label: "Internal ID"}),
               search.createColumn({name: "tranid", label: "Document Number"})

           ]
        });


       var runSearch=salesorderSearchObj.run();
      var results = runSearch.getRange({start: 0, end:999});
      var searchResultCount = salesorderSearchObj.runPaged().count;

        for (var i = 0; results != null && i < results.length; i++){
     // There should be no more than 1 result
            if (result.id) {
                // Load the SO                  
var salesOrderInternalId = results[i].getValue({name:'internalid'});
 }catch(e) {
     alrt("pageInit_ ERROR : " + e.message);
 }
}
}
}
return {

    updateRecord: updateRecord
};

});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...