In a UserEvent Script in View Mode, I need to chec...
# suitescript
j
In a UserEvent Script in View Mode, I need to check if a field is visible on the current form. It seems I cannot use
field.isDisplay
from the context.newRecord because this isn’t in dynamic mode. Any suggestions? Basically, I need to
form.insert()
a new field but only if a related field is visible on the form.
e
can you use form.getField() to determine if the field exists?
Copy code
var field = form.getField({
    id : 'textfield'
});
j
returns field even when field not visible
also
insertField
doesn’t actually put it where I want in UE
what the heck am I doing wrong here
e
so field.isDisplay returns true after you do a form.getField()?
j
field.isDisplay is only available in Dynamic mode.
context.newRecord is not in Dynamic mode.
Here’s what I’m kinda trying to achieve
Copy code
var my_pre_existing_field = context.newRecord.getField({fieldId: 'custbody_my_pre_existing_field'});

// Check somehow that this exists and is visible....


if(exists and is visible) {


	var my_new_field = context.form.addField({
		id: 'custpage_my_new_field,
		type: serverWidget.FieldType.URL,
		label: 'My New Field'
	}).defaultValue = my_url;

			
	context.form.insertField({field: my_new_field, nextfield:'custbody_my_pre_existing_field'});

}
to summarize:
Copy code
if(field_exists_and_is_visible)
	addNewFieldBeforeIt();
this is in UserEvent beforeLoad
e
you may have to deal with it using client-side script
j
cannot because View only
e
yes you can...just put your function before and outside the pageInit()
//these functions will fire everytime the page is loaded evaluateFormActions(); colorizeFields(); //NOTE: pageInit fires only on create or edit never on view function pageInit(context) { console.log('pageInit fired...');
j
wait what
this is news to me
😀 2
plusone 2
unfortunately my Transaction forms are using legacy 1.0 custom form client scripts….
e
yes since pageInit only fires on edit or create any function running outside of that pageInit will fire every time the page is loaded
what do you mean by using legacy 1.0 custom form client scripts?
plain JS should work client-side
j
I mean my client scripts for my Transaction Forms are in 1.0
e
like nlapi calls? that shouldn't matter the 2.0 code are simply wrappers for nlapi calls
j
like so:
message has been deleted
I’m very rusty on 1.0. Not sure how to create and insert field in 1.0
will have to go looking
e
search for SuiteScript 1.0 to SuiteScript 2.x API Map – Functions (nlapi) in help
j
yeah I don’t see anything there on create or insert field tho
I have apparently overwritten all my old brainspace allocated to 1.0 lol
🤭 1
ahh
form.addField
though, if I’m not in PageInit, I don’t know how I will access
form
m
I don't think you can add fields from client scripts. And the field is read only when you use .getField from a client script. Why not just try to force diplay type normal as long as the field exists?
Copy code
var my_pre_existing_field = context.newRecord.getField({fieldId: 'custbody_my_pre_existing_field'});

if (my_pre_existing_field) {
    my_pre_existing_field.setDisplayType('normal');
}
I don't any properties to query regarding whether it's hidden or not in the v1 documentation for
nlobjField
. I would try logging the object and seeing if you can find properties like
isDisplay
isHidden
...etc.
d
Hey @jen If you get the field from the form that is being loaded in the User Event beforeLoad script it will return null if the field is not shown on the form.
log.debug('form field',ctx.form.getField({id:'custbody_ks_bb_vendor_rep_list'}))
j
@dcrsmith that doesn’t seem to be true. I get the field definition even if the field is not ticked to be displayed on the form.
the
field
object that’s returned by
context.form.getField()
is the same regardless of whether or not it’s a form that shows the field.
d
Hmm, I just tested that and when "show" was not checked the beforeLoad script returned null. Maybe because the field I was looking at didn't have a value set? I could verify that...
Yah, on the custom form "show" if it's unchecked it returns nothing for me.
j
is definitely unticked on the form
but still getting this
message has been deleted
message has been deleted
d
😔😢
j
it doesn’t have a value on this record
326 Views