Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Auto Numbering with PowerAutoNumber for Required Fields

Post Author: Joe D365 |

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.

Auto numbering

Auto numbering

2. Set a place holder in PowerAutoNumber as {ProductIDNumber} as instructed in the User Guide.

Auto numbering

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.

Auto numbering

 

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.

Auto numbering

5. Once the form is saved, it will auto set ID to PowerAutoNumber as shown below:

Auto numbering

Auto numbering

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!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

PowerObjects Recommends