Hi Everyone, I hope you guys are well, I am receiv...
# suitescript
t
Hi Everyone, I hope you guys are well, I am receiving inbound shipment through script, which creates item receipts for POs. I want make some changes on item receipts and redirect to it later(Receiving One PO at one time only). The problem here is you don't get the internal id of receipts in return. I tried making a search to get the latest Item receipt for PO, but that doesn't give me any results. I think that is due to , when we receive through UI and submit Receive Inbound Shipment, that kind of triggers another job that creates Item receipts. (Same I am expecting in script, when we submit that record, that job to create Item reciept starts, but IR is not created yet) I think the problem with search is, it is executing before the item receipt is created in the system. How can I get the IR id in this case, I have to fill in some fields and overage on items and redirect to that IR.
b
you may want to do the redirect in client script
gives you options to display a spinner while waiting for the item receipt to create
t
I am using a suitelet, that creates Item receipts via inbound shipment receiving.
Now after submitting the Receive Inbount shipment record, I want to get the receipt created with that.
That is what I am not getting, that is the issue.
The problem here is you don't get the internal id of receipts in return. I tried making a search to get the latest Item receipt for PO, but that doesn't give me any results. I think that is due to , when we receive through UI and submit Receive Inbound Shipment, that kind of triggers another job that creates Item receipts. (Same I am expecting in script, when we submit that record, that job to create Item reciept starts, but IR is not created yet)
b
If the item receipt is not created yet, then you have to wait
I would not advise waiting serverside
t
What should I do now? I have to edit that item receipt and fill in overage. and then redirect.
Currently now I am in POST of suitelet.
b
Return a form
Add client script that checks for the item receipt on an interval
Navigate to the item receipt when found
Preferably have some sort of feedback telling the user to wait
t
and what about overages ?
Like I need to edit that, client is not the best option
I am left with one object that contains items and the overage quantity, as overage can't be set during receive from Inbound Shipment.
I can put that object back on form in hidden field and provide a button, but then process will have extra step.
b
you can edit the item receipt in your client script
and navigate to it when ready
t
Hello @battk, I am not able to submit the record in the client script Here is the code snippet.
require(['N/record'], function(record) {
    
try {
    
var receiptRecord = record.load({
        
type: record.Type.ITEM_RECEIPT,
        
id: 712706,
        
isDynamic: false,
      
});
      
var receiptLineCount = receiptRecord.getLineCount({ sublistId: "item" });
      
for (var receiptLine = 0; receiptLine < receiptLineCount; receiptLine++) {
        
var currentItem = receiptRecord.getSublistValue({
          
sublistId: "item",
          
fieldId: "item",
          
line: receiptLine,
        
});
        
var prevQuantity = Number(
          
receiptRecord.getSublistValue({
            
sublistId: "item",
            
fieldId: "quantity",
            
line: receiptLine,
          
})
        
);
          
receiptRecord.setSublistValue({
            
sublistId: "item",
            
fieldId: "quantity",
            
line: receiptLine,
            
value: prevQuantity + 5,
          
});
        
}
     
var receiptId = receiptRecord.save({
        
enableSourcing: false,
        
ignoreMandatoryFields: true,
      
});
    
} catch (error) {
        
log.error({
            
title: 'Error in main',
            
details: JSON.stringify(error)
        
});
    
}
});
I am getting this. I am not using that function or field object anywhere.
I tried using debugger and this works.
b
what does using the browser's debugger do
make the debugger pause on exceptions (including caught ones)
t
No, it worked in script debugger. showing error in browser console and on demand client script both.
b
you want the stack trace of the error that caused the problem
netsuite tends to hide the errors, so you have to set the debugger to pause on caught exceptions
t
I don't know how to do that in browser console. If you are trying to say in context of script debugger, I am not getting any error there.
I wonder if you can try the same code on your end. I have tested this in two netsuite accounts. Works in none.
I don't see any problem with that code.
b
since your code doesn't call that particular method, one of your lines is causing one of netsuite's internal functions to call it
you need to figure out which line, which is something the stack trace will tell you
you can try taking a look at the top level error (you can see the stack in your console's error message)
but that doesnt always work since netsuite's errors are not sane
t
Can same problem be with multiple accounts ?
If that is, that should be a problem in netsuite.
Stack looks like this :
b
tenth row is the interesting one here
its trying to do a field change
which is not something that a standard record does
try using dynamic mode
t
Yes, the dynamic mode works. Can't thank you more! . But still worried why it didn't work in standard mode.
b
its more of an internal netsuite thing, but netsuite sends scripts to be evaluated on your record
in this case, it looks like netsuite sent the wrong one
t
I have one more question, I believe dynamic mode is slower, than the standard mode. Like the time taken to perform any operation in both mode, sublist will be worse for dynamic mode. What are your thoughts on this ?
b
you are writing very optimized code if you are worrying about that
usual causes of slowness in scripts are things that use points
for client scripts, that also includes anything that makes a http request
for example, for serverside scripts, log.debug isnt usually a performance concern, but client side it is since each log represents a http request
t
Ohh, I didn't think that far.
b
you are probably worrying about the wrong things if you are worrying about standard vs dynamic
🆗 1
t
Also, I want to tell you I am putting details back to form, and in pageinit, I am doing this after 10 seconds using setTimeout.
receipt is created in that time. But I am saved from multiple saved search requests.
One thing is still a concern, how will I detect that this is the receipt just created, like in case the order was already partially fulfilled.
It might give me the old item receipt.
b
what does your search look like
t
Untitled
b
thats a little inexact
you should probably be doing an inbound shipment search
t
inbound why ?
b
it has an item receipt join
t
But there can be multiple receipts for one inbound.
I am receiving only one PO.
b
you can tell which purchase order an item receipt is related to
t
I got your point for inbound shipment, We are going towards more accurate by doing this.
Should I filter with something more ?
b
you may or may not need the today filter
if you need to support updates on the inbound shipment, then you are probably better off with a checkbox on the item receipt to note that it has already been processed and use that checkbox as a filter
t
ohhhh, yes you are right. but then will need to edit the receipt in case if there is no overage also. Currently I am editing the records which have overage items.
Since I am using descending order and picking up the latest, that should be fine now. But I am taking note of the checkbox filter.