hey everyone! I am trying to create a lead record ...
# suitescript
m
hey everyone! I am trying to create a lead record from data submitted in a form from a Suitelet. The error on
record.save({ignoreMandatoryFields:true});
says:
Copy code
"You must enter at least one line for sublist: Address",
So, you can create a lead record in the UI without an address, and the exact same lead creation code is working in a different Suitelet. Here is the code:
newCustomer = record.create({
type: record.Type.LEAD,
isDynamic: true
});
newCustomer.setValue({fieldId:'custform', value:-8});
newCustomer.setValue({fieldId:'firstname', value:firstName});
newCustomer.setValue({fieldId:'lastname', value:lastName});
newCustomer.setValue({fieldId:'email', value:caseEmail});
newCustomer.setValue({fieldId:'phone', value:casePhone});
newCustomer.setValue({fieldId:'isperson', value:'T'});
customerId = newCustomer.save({ignoreMandatoryFields:true});
Any ideas on what's wrong? Thank you!! edit: Oh, and all the variables have a value. The data is in the POST, so it's not like the form isn't posting. edit2: and yes, all these leads should be for an individual, so the
isperson
is just hard coded true. thanks again! edit3 (😅 ) in the other Suitelet where this works, the record that is created sets the first name and last name fields into the address sublist. However, there is nothing in that Suitelet that sets a sublist value.
c
If you set to false (or remove) isDynamic does it work? There's nothing you're doing here that I see that you would need to be in dynamic mode.
m
@creece no, same error if that is false.
everything, even the settings on the deployment, are or look identical to another Suitelet that creates the record.
a
does the other suitelet have a client script attached to it that is setting the sublist address to the names ?
eh, you'd still see it come back in the post. disregard
both suitelets are using the
-8
form?
m
yes, both are using the same form id
a
so there's multiple things going on here 1. NS is requiring an address in suitescript but doesn't in the UI 2. one version of the suitelet is somehow setting a fake address with the name, which apparently works 3. the other version that has the exact same code, doesn't magically set the address
m
I know, it sounds absurd
I keep thinking there is some stupid thing I've overlooked but I am not seeing it yet if there is
a
this is almost always the issue "I keep thinking there is some stupid thing I've overlooked"
I'm trying to figure out a way that one suitelet would trigger this magical address setup functionality, but the other one would not
they're the same style of suitelet? create form on GET create lead from form data on POST?
m
this is what the other Suitelet is doing for the address, but without any code that sets a sublist. And no workflows that I can find that might be doing something
a
even if there was a WF or a beforeSubmit UE, idk how it would trigger on one suitelet and not the other
m
yes, they both create the form on GET, but there is this difference: the working Suitelet creates the form entirely from the
'N/ui/serverWidget'
whereas the Suitelet throwing the error, the form is loaded from a template, like this:
let myHtml = file.load({id: '/SuiteScripts/dev/templates/customer-service-form-template.html'})
but the data makes it into the post and everything in the template HTML is named and id'ed with custpage_SomeFieldName Could that be the problem, though? That it's loaded from a template, even though all the data is in the POST? And the reason for the template on the non-working Suitelet is because it going to be a pretty involved UI and it looks better/is easier to just write the HTML, if that makes sense
a
I'm not sure how that difference could be impactful, the form html is just a vehicle to get the data back to suitelet on post to create the record
m
I have another Suitelet where I load a template like that instead of doing the ui.addForm() thing, and I am saving a PO record in that one, but, the PO already exists, it's not creating a new one. If the data is in the post, seems like it should work, but idk. If I have ever had issues with loading a template vs. ui.addForm, the data didn't make it to the post and that was because the form wasnt set; fixed that and it always worked.
it would really suck if I have to build this to requirements with the
'N/ui/serverWidget'
because there is a lot to the page.
a
better approach might be just to create a default address in this second suitelet
there's no other header fields being set in the post of the one that's working?
and there's not a call to a helper function which might be hiding the address creation?
e
Strange. My suspicion would normally be a WF or UE on the record, and that's still what I'd investigate here, but that seems less likely if a similar Suitelet works fine.
m
Thank you, @erictgrubaugh -- still haven't figured this one out. The UI behaves different from the other Suitelet and they both behave different than my Suitelet.
e
No Client Scripts in any of the scenarios?
m
The only client script is dealing with the Google recaptcha in the working Suitelet