The closest I can find is "Promotion Code" which a...
# suitescript
k
The closest I can find is "Promotion Code" which apparently corresponds to the
couponcode
field in Sales Orders, but when I try to add a line to the promotions sublist by entering
couponcode
and then committing the line, I get the error
Cannot read property 'dictionary' of undefined
. Any ideas what I'm doing wrong here?
r
One of the reason you are getting this error because when you are trying to insert a new line, client line level script is firing and it is looking for dictionary field which is not there. Try to set dictionary field value before you commit the line. Hope it helps
k
What is the dictionary field?
b
In my experience, committing new lines while already committing a line just leads to errors
For your specific code i recommend using the
forceSyncSourcing
option while setting the text
k
Do you mean
fireslavingsync
?
Should I just not commit the line?
b
you are now officially an old man.
Copy code
In 2019.1, options.forceSyncSourcing replaces the options.fireSlavingSync parameter
k
wow
Still the same with forceSyncSourcing
I'll try removing commitLine
b
the last time i had to commit extra lines in client script commitLine, I ending up using setTimeout
k
how so?
b
but if you keep on getting an error, you may want to look at the stack trace and find out what netsuite is doing
k
removing commitLine just made it not keep the promotion line 😞
b
I had issues committing a line while NetSuite was already busy committing a line
i used setTimeout to commit the line after netsuite finished committing the original line
k
setTimeout doesn't seem to change anything
setTimeout(salesRec.commitLine({ sublistId: 'promotions' }), 5000);
It doesn't seem to be waiting 5 seconds before trying it, either
My brain is super fried. Dunno what I'm doing wrong here.
b
You may want to lookup documentation on setTimeout
The first parameter is a function to run after the specified timeout finishes
k
isn't commitLine a function?
b
salesRec.commitLine() does not return a function
k
ah
b
you probably want something like
Copy code
setTimeout(function() {
  salesRec.selectNewLine({ sublistId: "promotions" });
  salesRec.setCurrentSublistText({
    sublistId: "promotions",
    fieldId: "couponcode",
    text: promoCode,
    forceSyncSourcing: true
  });
  salesRec.commitLine({ sublistId: "promotions" });
}, 5000);
k
yeah, I've got something very similar now. The only problem is it goes off after the save
I guess I could put a timeout on the record.save too
b
Is salesRec the currentRecord
k
no, it's loaded by record.load
record.create rather
yeah it doesn't like doing salesRec.save() inside of the timeout function 😕
b
The advice i gave is only relevant for client script currentRecord
k
Ah ok
Well, that's a bummer. Any other ideas? 😞
b
Is this client script
k
yeah, this is a client script running on a custom record
it currently creates a sales order when a button is clicked
but they want to add promotions to the automatically generated sales order based on a field on the custom record
so I added the promo code field to the custom record
and the above code to the script
Here's the current code, but it gets the same error...
Copy code
let promoCode = Number(rec.getValue({ fieldId: 'custrecord_promocode'})) | 0;
                    if (promoCode > 0){
                        salesRec.selectNewLine({ sublistId: 'promotions' });
                        salesRec.setCurrentSublistValue({ sublistId: 'promotions', fieldId: 'promocode', value: promoCode, forceSyncSourcing: true});
                        salesRec.commitLine({ sublistId: 'promotions' });
                    }
Works fine if I leave off the commitLine but of course doesn't save the promotion
b
You may want to look at the stacktrace of the error
Otherwise im unfamiliar with the new promotions module that netsuite released so im not sure if that is how you add promotions