I've created a UE script to run on before submit o...
# suitescript
s
I've created a UE script to run on before submit of a transaction record, and sets a field to record the user who created the transaction. This works great, apart from when a PO is created after an SO has been approved, and when an item fulfilment is created automatically by another UE script when a supplier bill is entered.
n
I think you can achieve what you want with just an additional submitFields(). But for some complex scenarios I faced in the past, I created a Suitelet which would do all the job of creation and that Suitelet is called by the UE before submit as in your case. It's not neat but does the job. You could create a Suitelet and send the value you want to set to that Suitelet and then that Suitelet will do the updates. When you submit a record in the Suitelet, it will trigger all the UE. Don't know if it's good enough for your scenario.
s
Here is the current code:
I am not sure a scheduled script would work as it would have to run straight after the record is created
function setCreatedBy() { nlapiLogExecution('DEBUG', 'Code Check', 'Record ID: ' + nlapiGetRecordId() + ' | Script Triggered'); // Get the internal ID of the current user var user = nlapiGetUser(); // If statement to check if the user variable returns -4 (user is -System-) if (user == -4) { // Set the 'this transaction created by' field to a blank value. The -System- user is not an employee so cannot be set in this field. nlapiSetFieldValue('custbody_this_transaction_created_by', null); } else { // Set the 'this transaction created by' field using the user variable nlapiSetFieldValue('custbody_this_transaction_created_by', user); } }
n
Well, I think your PO created upon approval of SO should have that field set correctly, unless in your before submit you have some 'IF' condition like when execution context is 'Create' only then the script runs. Because in case of approval the context I think comes as 'DROPSHIP' or 'Special Order'. You might wanna debug this part to understand what's happening but I am almost sure that the PO UE runs when the SO is approved and a PO is created for that SO. As for your Item Fulfillment conundrum, I would say you should edit your UE that is creating the Item fulfillment and in that UE, before finally submitting the Record, you should set that field. I know you created the script so you don't have to do this everywhere, but it is what it is. In all UE(s) where you are creating records, you will have to set the field manually.
Also, I think a neater way to do this would be to actually edit the form and set the default value of the field with Current User. I think that should resolve all your issues in this specific case. That way you don't need this script.