In this webinar, our experts showcase a variety of demo use cases of how different components of the...
One feature that can be difficult to achieve in Dynamics CRM without some development help is automatic unique numbering of entities. The ability to have Accounts, Phone Calls, or any custom entity that you create assigned a custom unique ID can be a huge aid in organizing and tracking records.
To help with this, PowerObjects has created a custom PowerPack solution called PowerAutoNumber that allows you to quickly and easily set up automatic numbering of any entity in Dynamics CRM 2011. All you need to do is install the solution, choose your ID format, and point it to the entity on which it should be applied. Once you have it set up, you can have an ID automatically added to any text or numeric field in any record in CRM. This ID can even include dates or information from another field on the record, and it takes no custom coding whatsoever.
You can try PowerAutoNumber for free, and learn how to use it in our short User Guide.
There is also a neat trick you can do by taking advantage of a little bit of JavaScript to create a unique ID number that dynamically includes the name of the customer (or any other name that you would like to pull) from a look-up field. For our demo, we are going to automatically populate the "Title" field of every case we create with an ID that starts with the name of the customer. Thus if the case is for Microsoft, and the current ticket number is 1019, the "Title" of our case will become Microsoft-1019
To do this:
Here we have set the Target Attribute (the field where PowerAutoNumber will add the ID) to "Title". We have also set Field Format to {f:new_powerhiddenfield}-{a:1}, which means that any number that PowerAutoNumber creates will start with the contents of the new_powerhiddenfield and be followed by a dash and the current number PowerAutoNumber is at.
var autofield = Xrm.Page.data.entity.attributes.get("customerid").getValue()[0].name;
Xrm.Page.data.entity.attributes.get("new_powerhiddenfield").setValue(autofield);
}
[/sourcecode]
The code above creates a function called autonumber. The second line grabs the name in text form of the record in the customerid field. The third line then writes that name to the new_powerhiddenfield on the form.
To get this code to work with whichever fields your application is using, just replace customerid with the look-up field that you wish to pull your name from, and new_powerhiddenfield with whichever field you have PowerAutoNumber set to use in creating its field format for creating IDs.
Then add the JavaScript as a web resource to the form you wish to use it on
and have it call the autonumber function on the onsave event.
The code will execute when you save your form, writing the name of the record from your look-up (in this case from the customerid field) to the hidden field (in this case new_powerhiddenfield). PowerAutoNumber will then fetch the information from your hidden field and use it in its field format.
Want to see more of Dynamics CRM can do with a little JavaScript magic?
Happy CRM'ing!