Basically I've got someone with a custom record ty...
# suitescript
k
Basically I've got someone with a custom record type from a bundle created by NetSuite which we can't modify, and which only allows record creation from the UI or CSV import. When I try to create the records via script we get an error from the custom record user event script saying we can't create it this way. When I bypass the user event script, the record doesn't trigger the tasks that need to happen after submit. So I'm left with two choices, I think. I can either use a script to do a CSV import generated via script based on user input, or I can borrow half the code from the custom record user event and trigger the tasks myself. I'd rather not muck around with NetSuite's code if I can help it though, so I was thinking if I could emulate a CSV import without actually doing a CSV import, I could correctly trigger the custom record user event.
m
The UE script from NS, is it before submit or after submit?
Also, can you please elaborate " When I try to create the records via script we get an error from the custom record user event script saying we can't create it this way."? Does it mean there are some validations that are not met while creating the record from script? What validations?
k
The custom record UE has some validation during beforeSubmit which fails with an error if the custom record is not created from the UI or a CSV import
m
What NS bundle is it - to give me some more background?
k
I bypassed the UE entirely, but then the records weren't triggering other processes anymore
Effective Date Pricing
I think I may have found a workaround though
m
Have you made sure your UE script is triggering before the Bundle UE script by adjusting the UE queue?
k
What is the UE queue? (aka, probably not!) 🙂
m
🙂 When you go to the screen where it lists all scripts deployed to a record, you can adjust the priorities in which the UE scripts execute.
You do that simply by moving them in the required order. I know it's counter-intuitive, but a nice thing to know 🙂
k
Oh ok
the issue is they want to create the custom records from the sales order line level instead of having to do them through the UI as NetSuite designed it
so I've created a couple custom transaction line fields and a script that takes the data and populates the custom records
so the UE isn't really running on the same record
there's the sales order script (client or user event, doesn't matter) which creates the custom record, and then there's the custom record user event
m
So your issue is with the custom record trigger, right?
k
yeah
near the beginning of the custom record UE it's got
if(!sslib.isEmpty(pricingUpdateID)){
which is a parameter passed to the UE from the UI
m
Do you have time for a call? That might be much easier. Than we can post the result in here.
k
not really, I'm swamped at the moment. XD
I'm chatting here while doing a million other things
m
You can't really pass a parameter to a UE script. It has to be getting the values from somewhere within NS.
So you need to find out where it's getting the parameter.
paremeter -- the object/value
k
it's getting the parameter from the created from passed via the get URL
m
UE is not able to get the URL as it's a server script. Needs to be stored somewhere.
b
you may save some time by simply uploading the script
🙂 1
m
Dunno how NS would like that as it's a locked bundle, but sure.
Also the library, please.
k
NSTS_EP_UE_PricingUpdatePrices.js
NSTS_SS_Lib_ObjectsAndFunctions.js
yeah I dunno what they think of that. I guess they can tell me not to. 😕
m
Missing the eplib library, please.
'../Library/NSTS_EP_Lib_Constants.js'
k
NSTS_EP_Lib_Constants.js
I get to line 171 of the user event every time I try to create from a script, if I create from a client script. If I create from a user event, it doesn't trigger the custom record user event so I don't get the error
m
var EP_PRICE_UPDATE_PRICES_RECORD = { ID: 'customrecord_nsts_ep_pricingupdateprices', FIELDS: { ID : 'internalid', PRICE_UPDATE : 'custrecord_nsts_ep_pricingupdate',
That's the field you need to populate.
That just means the bundle is creating more records. Not just the one you're now creating from you script.
k
yeah, I create the pricingupdate record first
then get the id and populate that field
but because this happens beforeLoad it never gets to the point where it can set the field
I think
m
Option 1: (I don't support this approach) Create exactly all the records as the Bundle is creating them and use their existing logic. Option 2: Change Request - never to be done I guess 😕
k
Copy code
let pricingUpdateRec = record.create({type: "customrecord_nsts_ep_pricingupdate"});

        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_updatetype", value: 3});
        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdateitem", value: itemId});
        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdatestartdt", value: startDate});
        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdateenddate", value: endDate});
        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_customer", value: customerId});
        pricingUpdateRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdatestatus", value: 1 });

        let pricingUpdateId = pricingUpdateRec.save({ignoreMandatoryFields: true});

        if (pricingUpdateId) {
          log.debug("Pricing Update record created: ", pricingUpdateId);

          let pricingUpdatePricesRec = record.create({ type: "customrecord_nsts_ep_pricingupdateprices" });

          pricingUpdatePricesRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdate", value: pricingUpdateId});
          pricingUpdatePricesRec.setValue({fieldId: "custrecord_nsts_ep_currency", value: 1});
          pricingUpdatePricesRec.setValue({fieldId: "custrecord_nsts_ep_pricingupdatenewprice", value: rate});
          pricingUpdatePricesRec.setValue({fieldId: "custrecord_nsts_ep_pupcustomer", value: customerId});
          pricingUpdatePricesRec.setValue({fieldId: "custrecord_nsts_ep_pupitem", value: itemId});

          let pricingUpdatePricesId = pricingUpdatePricesRec.save({ignoreMandatoryFields: true});

          if (pricingUpdatePricesId) {
            log.debug("Pricing Update Prices record created: ", pricingUpdatePricesId);
          } else {
            log.error("ERROR", "Failed to create Pricing Update Prices record.")
          }
        }
oops that was longer than it looked in webstorm
yeah I was thinking option 1 or CSV import via script, generated on the fly
the error occurs at
let pricingUpdatePricesRec = record.create({ type: "customrecord_nsts_ep_pricingupdateprices" });
before I get to the first setValue
m
You're saying part of the logic in that Bundle is intended for use with UI. Does it mean there are some CS scripts doing the actual work of creating any records?
k
I'm currently working on a workaround that's sort of an option1 lite that sets all the fields where they need to be on all the records and hope the bundle picks it up from there
no, there's a button on the pricing update record that creates the new pricing update prices record
m
Keep in mind that will not be compatible with future updates of the bundle.
k
and in the URL it includes a created from parameter
yeah I know but it'll work for now
m
I hate the "for now" part 🙂
k
the client scripts and user event mainly get the records set up for a map reduce to "activate" them later
so if I can just get it configured so the map reduce is happy, it should get the same effect
m
are you sure you're creating both records? customrecord_nsts_ep_pricingupdate customrecord_nsts_ep_pricingupdateprices
k
yeah
m
The error you're getting is "Pricing Update record is required to create a Pricing Update Prices record. Please create a Pricing Update record first." Right?
k
yeah
b
The beforeLoad on customrecord_nsts_ep_pricingupdateprices will prevent its creation on anything that triggers suitescript
k
the problem is that when you create from the UI, that field is populated before beforeLoad
you can't do that via SuiteScript that I know of
m
what about initial values in the record.create function? That could mimic it.
b
you might also want to include user event scripts on customrecord_nsts_ep_pricingupdate
👍 1
customrecord_nsts_ep_pricingupdate could be creating the customrecord_nsts_ep_pricingupdateprices, which will bypass user event scripts
m
In general - actually a bigger issue. UE does not trigger UE.
k
@battk That's brilliant if it'll let me.
I could deploy a new user event to the pricing update prices record
m
If you want to fix this - Call a SL from the UE to trigger the other UE.
k
put it before the existing one in the queue
have it populate the field
maybe only on xedit so it only happens when there's a script
regardless though, my option1 lite workaround worked 😄
👍 1
on my sales order user event, bypassing the pricing update prices user event, I set all the fields the map reduce needed.
then I run the map reduce and it finds it and activates it
m
That's the best option. If the source is right, there are now less dependencies with the bundle updates.