We are unable to get this script to run and just r...
# ask-stanley-ai
a
We are unable to get this script to run and just receive this error message when we save item receipts - An unexpected error has occurred. Please click <a href="javascript:window.open('/app/crm/support/nlcorpsupport.nl?l=T&type=bug&ticket=mt97f2nerxmi8q5v4mb8', 'Error','scrollbars=yes,toolbar=no,width=800,height=700');void(0)">here</a> to notify support and provide your contact information.
a
I can't see anything wrong with it at first glance. I would start by adding log.debug() lines at the beginning of afterSubmit(), and each other function declaration, and see which ones are firing before the error hits. If none of them hit before the error does, then there's a problem at a higher level, maybe syntax or script configuration.
r
Btw you are using lookup in a for loop. That's really gonna slow things down. If the item's receipt has too many lines and UE can potentially hit the governance limit bcz of it. Would be better to just query the data for all the items at once.
a
thanks both, it seems the script doesnt even get a chance to execute as there is nothing in the logs which is causing me confusion. This script also works fine in sandbox so any advice is greatly appreciated!
r
Check the deployment record. Make sure it's released, deployed and appropriate roles are selected. Check other user event scripts deployed on the record. One of them might be erroring out before this one can get executed.
a
thanks! I managed to get it to work by completely deleting the deployment, script, and file from file cabinet and reuploading. No idea what could have been causing it but seems to have resolved
a
Sometimes that's the way to fix it. Also @raghav is right. You'll really need to move the submitFields() call to a place in the code where all the data you want to submit has been set on the values, but it's not doing submitFields multiple times to the same record (because of the caller function calling the called function in a loop). I think the reasoning behind this was to make sure it would get every record updated since each line could refer to a different target record, but it is very easy to run out of governance and make the script run way too long. Might be better to run as a map/reduce or scheduled thing. There's also a new Event Subscriber script type that I'm going to learn about, and I wonder what its limits are.
r
I am not talking about submit fields, I am talking about lookup fields he has a custom function which is calling lookup in a for loop which is totally unnecessary.
a
I can't find the loop. He must have already fixed it.
r
Loop for item sublist, updateItemPrice function which in turn is calling lookup single select function in which he is doing lookup on item record.
145 Views