Has anyone ever set a field to mandatory or not in...
# suitescript
j
Has anyone ever set a field to mandatory or not in a user event script?
m
Yep. You just load the field and set isMandatory = true or false iirc.
j
Is that on before load?
Do you have any samples for that? I can't seem to find any documentation on it
m
Yeah. Let me see if I have an example in our codebase.
j
Thank you sir
j
To kind of go with the discussion above, I find this is one business need that workflows are just simpler to build and maintain that doing in a script... without knowing your specific application. 😉
m
That's a good point.
j
I agree, but i'm having a timing issue
The workflow reads a field value on entry. If there is no field value, it will set the fields to mandatory. However, the issue is the workflow triggers and doesn't see the field value
m
Copy code
var obj_email_field = context.newRecord.getField({fieldId: 'email'});
        obj_email_field.isMandatory = true;
Just tested that and it works.
We didn't have an example so I just made one.
Put it in your beforeLoad statement
j
That's great, thank you.
Of course Testing. I try not to role untested code into prod... it works... sometimes
Thank you for this, it worked great