Something puzzles me when it comes to Case/Task cr...
# suitescript
m
Something puzzles me when it comes to Case/Task creation. I have a Suitescript 2.1 script in which I want to programmatically create a Case, and a set of Tasks for it. The Case itself, no problem. I get it setup, save it with
let supportCaseId = supportCase.save();
and I have an InternalID in hand for use later. I prepare my task the same way, and supply it the case ID like so:
task.setValue({ fieldId: 'supportcase', value: supportCaseId });
Only, upon saving the task, I get hit with "You have entered an Invalid Field Value 21961989 for the following field: supportcase" I'm not too sure what I'm doing wrong here. In my mind, I'm supplying the Case's InternalID, so in theory it should work, but in practice that's not the case. 🤔 Any clues?
b
make a calendar task in the ui so that you know which fields you need to set
alternatively, match the default values that netsuite uses when you create a task from the support case
m
I made a mockup earlier for that purpose. For mandatory fields, I'm good. My real challenge is that I know which Related Case I want to give to my Task, but I'm not clear on how I'm supposed to express it in a way that NetSuite/SuiteScript will understand. Maybe I need to supply the
number
instead of the
internalid
?
b
select fields are internal ids
or alternatively text with setText, but there really is no reason to use the text if you have the internalid
m
Indeed, my thoughts as well. Which confuses me even more when NetSuite rejects that.
b
what does the rest of the code look like
m
Most of it is a series of
entity.setValue({ fieldId: 'stuff', value: value });
to fill in various mandatory fields.
b
you are going to need to share which fields you set
the values probably wont matter, but if nothing looks off the values may matter
generally you need to share enough code to reproduce the problem
m
Oh, sure. Here you go:
Copy code
[...]
let supportCaseId = supportCase.save();

let task = record.create({ type: record.Type.TASK, isDynamic: true });

let today = new Date();
today.setHours(0,0,0,0);

task.setValue({ fieldId: 'startdate', value: today });
task.setValue({ fieldId: 'duedate', value: today });
 task.setValue({ fieldId: 'supportcase', value: supportCaseId });

let taskId = task.save();
The support case gets created successfully, so I omit whatever's before that.
b
back to the original thing i said then
start at calendar task
make your task, make note of each field you set
you need to set the same fields, in the same order that you do in the ui (since you are using dynamic mode)
m
I think I spotted the missing link. Initially the Related Case list comes up entirely blank - it "sees" nothing. Meanwhile, the Company field isn't mandatory, but it isn't set. After setting that Company, then does the Related Case show me a selection of Cases to choose from. So! Going off that find, let's see... 🛠️
Aaaaand, bingo! 🎉 I've got a Case, it's got a Task inside of it. Okay! So, I gotta keep not-mandatory-but-actually-mandatory fields in mind.
Thanks! 😊 I should be good to go from here on out.