Hi All. I'm having trouble reading a purchase orde...
# suitescript
j
Hi All. I'm having trouble reading a purchase order id from the purchase order sublist on a vendor bill. On the attached screenshot you can see that the "poid" contains the PO id. I am able to read the "id" and "linkurl" fields, but any others come back as undefined. Below is a sample snippet of how i am reading the fields in the sublist record. Any ideas? Thanks!
Copy code
var poListCount = myRecord.getLineCount({
	sublistId: 'purchaseorders'
});

var activePoCount = 0

while (activePoCount < poListCount) {

	var mypoId = myRecord.getSublistValue({
	    sublistId: 'purchaseorders',
	    fieldId: 'poid',
	    line: activePoCount

	activePoCount++
}
e
I've run into the same issue before. I was forced to use search.lookup to retrieve the PO name from the ID
j
@blackTshirt Thanks Eric, i will look into that. Do you know what the "cost" of that call is? I am currently doing a record.load of type PURCHASE_ORDER, which is 10 points. works perfectly, except if i have over 100 items in the PO Bill, the script exits with an error of reaching the 1000 point limit (100 x 10).
e
search.lookup costs 1 point/unit
j
yep, i just saw that. that might just work then. I'll give it a shot. I would really like to know why the poid is undefined though. I have seen this in the past as well. I'll let you know how I make out
e
It would be weird for me to NOT have tried this... but did you try
.getSublistText
instead of
.getSublistValue
?
j
I'll try it now...
@blackTshirt nah, still no go... worth a try though
Perhaps @michoel knows. After all, his "NetSuite Field Explorer" can read it..
b
probably want to start looking into stuff like permission issues
Copy code
require(["N/record"], function (record) {
  var myRecord = record.load({ type: "vendorbill", id: 28956 });

  var poListCount = myRecord.getLineCount({
    sublistId: "purchaseorders",
  });
  var activePoCount = 0;
  while (activePoCount < poListCount) {
    var mypoId = myRecord.getSublistValue({
      sublistId: "purchaseorders",
      fieldId: "poid",
      line: activePoCount,
    });
    log.debug(activePoCount, mypoId);
    activePoCount++;
  }
});
works fine for me
message has been deleted
e
interesting... come to think of it - I was using a similar call on an external suitelet - so a permission issue is very plausible. @JR whats the context of your script?
j
hmm, interesting... I have a user event script that creates a "Reconcile Bill" button when the Vendor Bill is opened. you can see the code below. It simply executes my function from my client script file.
Copy code
// 2.0
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */

define(['N/record', 'N/ui/serverWidget' ], 

    function(record) 
    {
	return {
		beforeLoad : function(context){
			var form = context.form;
			form.addButton({
				id : "custpage_addcreditcardfee_button",
				label : "Reconcile Bill",
				functionName : "reconcile_bill"
			});
			form.clientScriptModulePath = "/SuiteScripts/reconcile_bill_cl.js";
		}
	}
});
The top of my client script looks like this
Copy code
/**
 	* @NApiVersion 2.x
	* @NScriptType ClientScript
 	* @NModuleScope SameAccount
	*/

define(['N/record', 'N/currentRecord', 'N/search', 'N/runtime', 'N/ui/dialog', './utilities/lodash'], 
	function (record, currentRecord, search, runtime, dialog, _) {

......

 	function reconcile_bill() {
b
try loading the record instead of using the current record
j
@battk @blackTshirt battk's, suggestion worked! i used the following below and now i can get the poid. the other fields are still undefined, but i don't need them. Thanks to both of you for your help! #teamwork
Copy code
var curRecord = currentRecord.get();
		var curRecordId = curRecord.getValue ({
				fieldId: 'id'
			});

		var myRecord = record.load({
			type: record.Type.VENDOR_BILL,
			id: curRecordId,
			isDynamic: true
		});