In this webinar, our experts showcase a variety of demo use cases of how different components of the...
Using the PowerAutoNumber solution from PowerObjects automatically creates a number when an entity is first saved. In today's blog, we'll show you how to use PowerAutoNumber to set a system required field with auto numbering.
The system required field has to be filled out before you save. The PowerAutoNumber solution generates the automated number during creation, which occurs when a user saves. Here are the steps needed to save PowerAutoNumber into a system required field automatically.
1. First, create a hidden text field on the form you wish to have the automatic number added to. In our example, we've created a single line text field named po_autonumberhiddenfield and unchecked the Visible by Default box in its properties, thus making it a hidden field.
2. Set a place holder in PowerAutoNumber as {ProductIDNumber} as instructed in the User Guide.
3. Create the JavaScript which we have named PowerAutoNumber Field.js. This initially sets the system required field: Product ID to {ProductIDNumber} onLoad for Form Creation.
function autonumber_onload() { try { var type = Xrm.Page.ui.getFormType(); var productautonumber = Xrm.Page.data.entity.attributes.get("name").getValue(); if (type = 1) //Create { if (productautonumber == null) { Xrm.Page.data.entity.attributes.get("productnumber").setValue("{ProductIDNumber}"); Xrm.Page.data.entity.attributes.get("productnumber").setSubmitMode("always"); Xrm.Page.data.entity.attributes.get("po_autonumberhiddenfield").setValue("Init"); } } else if (type == 2) { var autonumber = Xrm.Page.data.entity.attributes.get("po_autonumberhiddenfield").getValue(); if (autonumber == "Init") { Xrm.Page.data.entity.attributes.get("po_autonumberhiddenfield").setValue("Created"); Xrm.Page.data.entity.save(); } } } catch (e) { alert(e.Description); } }
4. Next, add the JavaScript as a web resource to the appropriate form.
5. Once the form is saved, it will auto set ID to PowerAutoNumber as shown below:
That's all for the blog today! Our PowerPacks are the ultimate solution for taking Dynamics CRM to the next level! Go ahead, become a CRM superhero and download one of our many add-ons for a FREE 30-day trial!
Happy CRM'ing!