Hello Everyone, I have got a situation with a scr...
# suitescript
m
Hello Everyone, I have got a situation with a script in which I am trying to generate Item Fulfilments with Assembly Lot Number Items. In this particular instance, I have got an Line Item with Order Quantity of 4 and first lot # that I get from my search query for the Item / Location Combination, has 1 quantity available. Now in this instance, do I use to allocate Inventory Detail
Copy code
IFRecord.createCurrentLineItemSubrecord('item', 'inventorydetail');
Or
Copy code
IFRecord.editCurrentLineItemSubrecord('item', 'inventorydetail');
As its currently throwing this error: Code: CANNOT_EDIT_SUBRECORD Details: Cannot edit this subrecord, it is either in readonly state or dead state. Any guideline / help would be highly appreciated. Thanks Mrudul
b
what does your item fulfillment look like when you click the fulfill button in the ui
and what does the item selection code look like
im looking to make sure that the line you are trying to modify actually and an inventory detail record to modify
m
@battk: In my script I am looping through the items and performing a Search to see if there is any quantity in Stock at the line Location and when there is stock I perform the Lot # lookup and this is what I am trying with the script.
else if (Number(qtyavl) < itemqty) { //converted qtyval to Number
nlapiLogExecution('ERROR', 'suit_SO_Fulfillment', 'qtyavl<Lineitemqty');
var remqty = parseFloat(0);
if (LotitemSearch.length > 1) {
var first = 'F';
remqty = itemqty - qtyavl;
var bodyInventoryDetail = IFRecord.viewCurrentLineItemSubrecord('item', 'inventorydetail');
nlapiLogExecution('ERROR', 'bodyInventoryDetail', bodyInventoryDetail);
if (!bodyInventoryDetail) {
nlapiLogExecution('ERROR', 'create', 'invenassignment');
bodyInventoryDetail = IFRecord.createCurrentLineItemSubrecord('item', 'inventorydetail');
} else {
nlapiLogExecution('ERROR', 'edit', 'invenassignment');
bodyInventoryDetail = IFRecord.editCurrentLineItemSubrecord('item', 'inventorydetail');
}
for (var j = 0; j < LotitemSearch.length; j++) {
var itmqtyavl = parseFloat(0);
var itmcolumns = LotitemSearch[j].getAllColumns();
var itmlotno = LotitemSearch[j].getValue(itmcolumns[1]);
itmqtyavl = LotitemSearch[j].getValue(itmcolumns[2]);
var itmexpdate = LotitemSearch[j].getValue(itmcolumns[3]);
if (first == 'F') {
bodyInventoryDetail.selectNewLineItem('inventoryassignment');
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber', itmlotno);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', itmqtyavl);
bodyInventoryDetail.commitLineItem('inventoryassignment');
bodyInventoryDetail.commit();
first = 'T';
} else {
if (remqty >= itmqtyavl) {
bodyInventoryDetail.selectNewLineItem('inventoryassignment');
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber', itmlotno);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', itmqtyavl);
bodyInventoryDetail.commitLineItem('inventoryassignment');
bodyInventoryDetail.commit();
if (remqty == itmqtyavl) {
IFRecord.commitLineItem('item');
break;
}
remqty = remqty - itmqtyavl;
} else if (remqty > 0) {
bodyInventoryDetail.selectNewLineItem('inventoryassignment');
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'receiptinventorynumber', itmlotno);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', remqty);
bodyInventoryDetail.commitLineItem('inventoryassignment');
bodyInventoryDetail.commit();
IFRecord.commitLineItem('item');
break;
}
}
}
// break;
}
}
b
too much code
if this is giving you problems, you should simply try a smaller script in the debugger
Copy code
var iFRecord = nlapiTransformRecord(
  "salesorder",
  "whatever your id is",
  "itemfulfillment",
  { recordmode: "dynamic" }
);
iFRecord.selectLineItem("item", "whateverLineIsGivingYouTrouble");
iFRecord.createCurrentLineItemSubrecord("item", "inventorydetail");
m
Thank you,
I will see how i go..
Just a Question: if I am adding more then 1 line to Inventory Assignment, do I have to use " editCurrentLineItemSubrecord" for second line onwards?
b
no, treat it as a normal record and commit line by line
a quick look at your code tells me that you should probably use issueinventorynumber vs receiptinventorynumber if you get there
m
issueinventorynumber = Do i supply internal id of Lot # in this case?
b
yes
m
sorry to be pain, but I am still struck at being able to insert second line for Inventory details. See the code snapshot and see if something obvious is not right. thanks in advance.
Copy code
for (var j = 0; j < LotitemSearch.length; j++) {
							  var bodyInventoryDetail = IFRecord.viewCurrentLineItemSubrecord('item', 'inventorydetail');
							  nlapiLogExecution('ERROR', '214 bodyInventoryDetail', bodyInventoryDetail);
							  if (bodyInventoryDetail == null) { //Modified by Mrudul
								  nlapiLogExecution('ERROR', 'create', 'invenassignment');
								  bodyInventoryDetail = IFRecord.createCurrentLineItemSubrecord('item', 'inventorydetail');
							  } else {
								  nlapiLogExecution('ERROR', 'edit', 'invenassignment');
								  bodyInventoryDetail = IFRecord.editCurrentLineItemSubrecord('item', 'inventorydetail');
							  }
							   
								var itmqtyavl = parseFloat(0);
								var itmcolumns = LotitemSearch[j].getAllColumns();
								var itmlotno = LotitemSearch[j].getValue(itmcolumns[0]); //changing to 0
								itmqtyavl = LotitemSearch[j].getValue(itmcolumns[2]);
								var itmexpdate = LotitemSearch[j].getValue(itmcolumns[3]);
								if (first == 'F') {
									bodyInventoryDetail.selectNewLineItem('inventoryassignment');
									bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'issueinventorynumber', itmlotno);
									bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
									bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', itmqtyavl);
									//bodyInventoryDetail.commitLineItem('inventoryassignment');
									//bodyInventoryDetail.commit();
									first = 'T';
									nlapiLogExecution('ERROR', 'first', first);
								} else {
								  nlapiLogExecution('ERROR', '241 Else ', remqty+ ' >= ' +itmqtyavl);
									if (remqty >= itmqtyavl) {
										bodyInventoryDetail.selectNewLineItem('inventoryassignment');
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'issueinventorynumber', itmlotno);
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', itmqtyavl);
										//bodyInventoryDetail.commitLineItem('inventoryassignment');
										//bodyInventoryDetail.commit();
										if (remqty == itmqtyavl) {
											IFRecord.commitLineItem('item');
											break;
										}
										remqty = remqty - itmqtyavl;
									} else if (remqty > 0) {
									  nlapiLogExecution('ERROR', '255 Else if', remqty+ ' >= ' +itmqtyavl);
										bodyInventoryDetail.selectNewLineItem('inventoryassignment');
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'issueinventorynumber', itmlotno);
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'expirationdate', itmexpdate);
										bodyInventoryDetail.setCurrentLineItemValue('inventoryassignment', 'quantity', remqty);
										
										break;
									}
								}
									bodyInventoryDetail.commitLineItem('inventoryassignment');
									bodyInventoryDetail.commit();
									IFRecord.commitLineItem('item');
							}
b
are you trying to do automatic lot assignment?
m
yes
we are trying to create fulfilment with allocations in bulk
b
will you have to handle weird cases like duplicate line items on different rows?
m
yes, we have allowed for that in other part of the code before we get into this.
b
i can tell you that you don't generally need to treat the first item any different than the second
or third
m
Copy code
var bodyInventoryDetail = IFRecord.viewCurrentLineItemSubrecord('item', 'inventorydetail');
                                                      nlapiLogExecution('ERROR', '214 bodyInventoryDetail', bodyInventoryDetail);
                                                      if (bodyInventoryDetail == null) { //Modified by Mrudul
                                                          nlapiLogExecution('ERROR', 'create', 'invenassignment');
                                                          bodyInventoryDetail = IFRecord.createCurrentLineItemSubrecord('item', 'inventorydetail');
                                                      } else {
                                                          nlapiLogExecution('ERROR', 'edit', 'invenassignment');
                                                          bodyInventoryDetail = IFRecord.editCurrentLineItemSubrecord('item', 'inventorydetail');
                                                      }
its this part of code that is creating more trouble i suppose. as when we have multiple lot to be assigned to single line, we need to be careful with where we commit the assignment and item line.
b
thats probably the easiest part, and you don't really need to view the current line to do it
either createCurrentLineItemSubrecord is empty or editCurrentLineItemSubrecord is empty
so you can simply do
Copy code
IFRecord.selectLineItem("item", 'whateverLineYouAreOn')
var bodyInventoryDetail =
  IFRecord.createCurrentLineItemSubrecord("item", "inventorydetail") ||
  IFRecord.editCurrentLineItemSubrecord("item", "inventorydetail");
though i think its supposed to be createCurrentLineItemSubrecord
m
Hi @battk, Thank you for all your help. I have now managed to fix the issue.