Auto fill in Name field in Microsoft CRM 2011 entity
I want to fill in the name field for a custom entity in Microsoft Dynamics CRM 2011. I wrote a function that will be triggered in the onsave trigger for this entity.
This function works perfect when this field is not required. But they want this field to be business required. So when i try to save a new record, i get a message that this field must be filled in. Which means 开发者_JS百科my onsave function is never called.
here's my code that is called when saving the record:
var ls_string = "";
// put some text in ls_string
var myName = "";
if (myName != Xrm.Page.getAttribute("name").getValue()) {
Xrm.Page.getAttribute("name").setValue(ls_string);
Xrm.Page.getAttribute("name").setSubmitMode("always");
}
Hmm, well depending on where the Text in ls_string
comes from, you could do the population of the name field before the save event is fired.
A typical example would be, when either the "First Name" or "Last Name" field changes, then update the name field to be "First Name" + "Last Name".
However, using client script to fill in fields isn't necessarily the best plan. It's better to use a Plugin to enforce business logic, to avoid any loopholes.
This doesn't help if the field is Business Required, but I don't see what advantage that flag actually gives you... If you really, really need the business required flag, then you would fill in a bogus value in the client script, and always overwrite it in the plugin.
精彩评论