what actually happens
when we give
1)a!textField(
label:"First Name",
value:ri!emp.firstName,
saveInto:ri!emp.firstName
)
2)a!textField(
value:index(ri!emp,"firstName",null),
or
value:property(ri!emp,"firstName",null),
in what scenario's we need to use first one / second one...
Discussion posts and replies are publicly visible
index() and property() have the same functionality. You use index() or property() to access a field which is not guaranteed to exist. Like in a nested CDT as rule input with some parts being null.
From a functional perspective, there is not difference between the three options.
Does that answer your question?
yup, Mostly..,what is preferrable mostly...,either using ri!emp.firstName/index..? in value:
If your rule input is flat (no nesting) then use dot-notation, else index()/property(). In general, if you know that the field is ALWAYS available, use dot-notation. If there is a slight chance that the field does not exist, then use index().
As Stefan mentioned, index() and property() have the same functionality. For code clarity, though, I *STRONGLY* recommend people use property() when fetching a dot property, and reserve index() for fetching an index (i.e. a position within an array). Hence their names. I make this a required 'best practice' in all projects I lead.
Additionally, one use case for property() with a flat CDT is during enhancements when a new field is added - if you have running process instances which may utilize the prior version of the CDT, missing the new field, you can eliminate errors with something like below (example if Middle Name were added post go-live):
a!localVariables( local!cdt: { firstName: "John", lastName: "Doe", /*middleName: "M"*/ }, { a!textField( label: "First Name", value: local!cdt.firstName, saveInto: local!cdt.firstName ), a!textField( label: "Middle Name", showWhen: not(isnull(property(local!cdt,"middleName",null))), value: local!cdt.middleName, saveInto: local!cdt.middleName ), a!textField( label: "Last Name", value: local!cdt.lastName, saveInto: local!cdt.lastName ) } )
Great, Thank you