Dynamics CRM Client-Side Scripting
Hello everyone~(=゚ω゚)ノ
This is the usual blog written by the Product Development Department~(*^^)v
These days, the rainy season is dragging on and I'm getting really stressed out. I wish it would just clear up already... It's been a little over a year since I moved from Kansai, and I still can't get used to the heat in Tokyo (how about a little chat? lol)
Now, let's try writing some JavaScript.
While using Dynamics CRM, I was thinking that it would be nice to make screen operation a little easier, so this was one of the things I was thinking about when thinking about what kind of operation would be best.
So, let's get excited!
Using client-side scripts
The goal is to use client-side scripting (javascript) for lists and forms to create screen transitions that make input easier.
Have you ever felt it was a pain to have to navigate through different screens every time you want to create a record for a related entity?We have good news for you!
Outline
Create an opportunity record from the account form, and then edit the opportunity record while the account form is still open.
Typically, you would create an opportunity from a subgrid on the Account form or from Quick Create in the navigation bar.
In the former case, the screen may change automatically.(No way! I don't want to transition!)
With the latter, you have to set up the search fields for your business partners yourself, which can be a bit of a pain, right?
This is the result of considering whether we could make it a little easier.
Operating Procedure
- Click "Create a case" on the command bar of the client form
- The quick create form for an opportunity will be launched
- Enter the opportunity information in the quick creation form for the opportunity and click [Save].
- Open the created sales opportunity record in a separate window and make it editable
We'll show you how to achieve this later.
JavaScript implementation
First, let me show you the whole sample.
if (typeof artisan == 'undefined') {
artisan = { __namespace: true };
}
artisan.account = {
/*
* Call up a simplified sales opportunity creation form from the client company's form.
* Opens the created record in a separate window.
*/
createOpportunity: function () {
// Do not process if the form has not been modified.
if (Xrm.Page.ui.getFormType() != 2) {
return;
}
// Get information about the open record
var typeName = Xrm.Page.data.entity.getEntityName();
var id = Xrm.Page.data.entity.getId();
var name = Xrm.Page.data.entity.getPrimaryAttributeValue();
var reference = { "entityType": typeName, "id": id, "name": name};
/*
* Open the simplified creation form
* First argument: LogicalName (name) of the simplified creation form
* Second argument: The Reference of the entity that called the simplified creation form.
* Third argument: An object that sets the default values for the fields in the simplified creation form.
* Fourth and fifth arguments: Callback functions for success and failure.
*/
Xrm.Utility.openQuickCreate(
'opportunity', reference, null
).then(artisan.account.successCallback, artisan.account.errorCallback);
},
/*
* A function called when the simplified creation form is successfully overwritten and saved.
* The parameter object is set to only the savingEntityReference.
*/
successCallback: function (object) {
/*
* Opens the created record in a separate window.
* param: Parameters (query string) to pass to window.
*Option: Specify openInNewWindow:true to open in a separate window.
*/
var param = { "navbar": "entity" };
var option = { "openInNewWindow": true };
Xrm.Utility.openEntityForm(
object.savedEntityReference.entityType,
object.savedEntityReference.id, param, option);},
/*
* A function that is called when an error occurs when overwriting and saving in the simplified creation form.
* The `errors` parameter will contain the error code and error message.
*/
errorCallback: function (errors) {
var msg = "Error code: " + Errors.errorCode;
msg += "nMessage: " + errors.message;
Xrm.Utility.alertDialog(msg, null);
},
__namespace: true
};
createOpportunity function
Here, the processing is terminated for all other cases so that the form only works when updating.
if (Xrm.Page.ui.getFormType() != 2) {
return;
}
This is where we get information about our business partners.
Xrm.Page.data.entity.getEntityName retrieves the entity name, Xrm.Page.data.entity.getId retrieves the primary key, and Xrm.Page.data.entity.getPrimaryAttributeValue retrieves the value of the primary field.
Using these three pieces of information, the object that can be set in the search field called EntityReference is stored in a variable called reference.
var typeName = Xrm.Page.data.entity.getEntityName();
var id = Xrm.Page.data.entity.getId();
var name = Xrm.Page.data.entity.getPrimaryAttributeValue();
var reference = { "entityType": typeName, "id": id, "name": name};
This code invokes the opportunity quick create form and sets the value for the account field.
Xrm.Utility.openQuickCreate(
'opportunity', reference, null
).then(artisan.account.successCallback, artisan.account.errorCallback);
successCallback function
The successCallback is called if the record creation is successful in the quick create form. It passes the savedEntityReference as an argument, which is used to open the entity form (opportunity) in a separate window.
The param variable navbar specifies the state of the navigation bar of the opened entity form. The option variable specifies whether to open it in a separate window. The param variable can be used to set whether to show or hide the command bar, as well as other default settings.
Now the created opportunity will open in a separate window.
var param = { "navbar": "entity" };
var option = { "openInNewWindow": true };
Xrm.Utility.openEntityForm(
object.savedEntityReference.entityType,
object.savedEntityReference.id, param, option);
errorCallback function
The errorCallback is called if an error occurs in the quick create form (it is not called for client-side checks such as required checks).
var msg = "Error code: " + Errors.errorCode;
msg += "nMessage: " + errors.message;
Xrm.Utility.alertDialog(msg, null);
All you need to do is add a button to your command bar and call this javascript from there.
Actual screen movement
Now let's take a look at the actual screen.
1. Open an already registered business partner.

2. Clicking the [Create Opportunity] command will open the [Sales Opportunity] quick creation form.

3. Enter values into the fields and click Save.

4. The record you created will open in a separate window.

You'll notice that there's no site map information in the navigation bar, and no advanced search or quick creation options. Also, being able to work side-by-side in windows seems like it would increase efficiency! (Though that's up to you...)
Summary
So what do you think?! Don't you think it was easy to change the registration process?(Woohoo, clap, clap)
This is also something that ARCUS JapanDynamics CRM Training,Operation and maintenance/establishment support servicesIf you are interested, please contact us m(_ _)m
*The content of this article is for personal reference only. Please use the content of this article at your own discretion.
Related articles and pages
Person who wrote this article
Articles in the same category
-
One with One Marketing: Practical Application — Theory, Day by Day […] -
How to explain CRM 4.0 at a management meeting — "Another buzzword..." -
Checklist for Graduating from Excel Management — "I think I've reached my limit..." -
The limitations of continuing to manage sales using Excel templates — "It's convenient, but..." -
[EMOROCO CRM Lite Feature Introduction] Part 2: Enti[…] -
Reasons why you might not notice customers leaving — "I never thought so..." [...]
