英文:
Create Item fulfillment for selected items
问题
这是我的Suitelet 2.0,我想要为所选项目创建物品履行,并且如果项目、数量和批号与销售订单的项目、数量和批号不匹配,则显示错误消息。否则创建物品履行。请帮忙!
var form = serverWidget.createForm({
title: "创建物品履行"
});
form.addSubmitButton({ label: '提交' });
var soNumber = form.addField({
id: 'custpage_so_number',
type: serverWidget.FieldType.TEXT,
label: '销售订单号'
});
var sublist = form.addSublist({
id: "item_sublist",
type: serverWidget.SublistType.INLINEEDITOR,
label: "物品"
});
sublist.addField({
id: "itemname",
type: serverWidget.FieldType.SELECT,
label: "物品",
source: "item"
});
sublist.addField({
id: "lotnumber",
type: serverWidget.FieldType.TEXT,
label: "批号/炉号"
});
sublist.addField({
id: "quantity",
type: serverWidget.FieldType.TEXT,
label: "数量"
});
}
catch(e)
{
log.debug("获取时出错", e);
}
context.response.writePage(form);
}
else if (context.request.method === 'POST') {
try{
log.debug("Suitelet正在提交")
}catch(er)
{
log.debug("提交方法中出错", er);
}
}
}
英文:
This is my suitelet 2.0 and I want to create item fulfillment for selected items also shows the error message if the item, quantity, and lot number do not match with the sales order item, quantity, and lot number. else create item fulfillment. Please help!
var form = serverWidget.createForm({
title: "Create Item Fulfillment"
});
form.addSubmitButton({ label: 'Submit' });
var soNumber = form.addField({
id : 'custpage_so_number',
type : serverWidget.FieldType.TEXT,
label : 'Sales Order Number'
});
var sublist = form.addSublist({
id: "item_sublist",
type: serverWidget.SublistType.INLINEEDITOR,
label: "Item"
});
sublist.addField({
id: "itemname",
type: serverWidget.FieldType.SELECT,
label: "Item",
source: "item"
});
sublist.addField({
id: "lotnumber",
type: serverWidget.FieldType.TEXT,
label: "Lot/Heat Number"
});
sublist.addField({
id: "quantity",
type: serverWidget.FieldType.TEXT,
label: "Quantity"
});
}
catch(e)
{
log.debug("error in get",e);
}
context.response.writePage(form);
}
else if (context.request.method === 'POST') {
try{
log.debug("suitelet is posting")
}catch(er)
{
log.debug("error in post method",er);
}
}
}
});
答案1
得分: 0
以下是翻译好的部分:
你的代码非常简洁,但没有演示数据是否加载到你在Suitelet中创建的字段中。根据你分享的内容,你需要添加另一列,允许用户选择他们要履行的项目。
示例 - 在你的Suitelet中添加一个可点击的复选框:
sublist.addField({ id: 'custpage_apply', label: '选择要履行的项目', type: serverWidget.FieldType.CHECKBOX });
接下来,你需要在代码的POST语句中读取这个新复选框;只有当复选框被标记为TRUE时,才尝试履行订单。
示例:
...上面的GET代码....
else if (context.request.method === 'POST') {
//开始:创建履行对象,链接到销售/采购订单:
var objRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: {id},
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: false,
});
try{
//获取表格行数
var getCount = context.request.getLineCount('item_sublist');
for (var i = 0; i < getCount; i++) {
var isApply = context.request.getSublistValue({
group: 'item_sublist',
name: 'custpage_apply',
line: i
});
if (isApply == 'T') {
//添加代码以跟踪和标记匹配的项目以履行
}
}
record.save(objRecord);
context.response.write('履行现已保存');
}catch(er)
{
log.debug("post方法中发生错误",er);
context.response.write('发现错误 ' + er);
}
}
英文:
Your code is very brief and does not demonstrate whether data is loading into the fields you have created in your Suitelet. Working with what you have shared, you will want to add another column that would allow a user to SELECT the item they want to fulfill.
Example - adding a clickable checkbox in your Suitelet:
sublist.addField({ id: 'custpage_apply', label: 'Select Item to Fulfill', type: serverWidget.FieldType.CHECKBOX });
Next, you will want to read this new checkbox in your POST statement of the code; whereby you only attempt to fulfil an order when the checkbox is marked TRUE.
Example:
...GET code above....
else if (context.request.method === 'POST') {
//BEGIN: Create fulfillment object, link to sales/purchase order:
var objRecord = record.transform({
fromType: record.Type.SALES_ORDER,
fromId: {id},
toType: record.Type.ITEM_FULFILLMENT,
isDynamic: false,
});
try{
//Capture table line count
var getCount = context.request.getLineCount('item_sublist');
for (var i = 0; i < getCount; i++) {
var isApply = context.request.getSublistValue({
group: 'item_sublist',
name: 'custpage_apply',
line: i
});
if (isApply == 'T') {
//ADD CODE TO TRACK and MARK MATCHING ITEM TO FULFILL
}
}
record.save(objRecord);
context.response.write('FULFILMENT NOW SAVED');
}catch(er)
{
log.debug("error in post method",er);
context.response.write('ERROR FOUND ' + er);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论