Create your own utility
Yet this is very easy process but still a few of us still
need an understanding of how to use Managed solution as a utility in CRM. Here
I am going to describe it in very easy process.
So get ready to have your own personal utility.
Prepare your web resource:
Firstly, you have to decide what you want to do J.
So I just started thinking the least error prone (and easy
too J)
is simply creating an account by passing some fields.
Here we are going to create a HTML Web resource that will
create an Account. We will pass “Name” and “Phone” for account (you can add
more fields) and that will create a record in CRM.
Following is the code for that:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta
charset="utf-8" />
<title></title>
</head>
<script type="text/javascript">
function
createAccount()
{
var
accountName = document.getElementById("name");
var
accountphone = document.getElementById("phone");
callAPI(accountName.value,accountphone.value);
}
function
callAPI(name, phone) {
var entity =
{};
entity.name =
name;
entity.address1_telephone1 = phone;
var req = new
XMLHttpRequest();
req.open("POST", window.parent.Xrm.Page.context.getClientUrl()
+ "/api/data/v8.0/accounts", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json;
charset=utf-8");
req.onreadystatechange = function () {
if
(this.readyState === 4) {
req.onreadystatechange = null;
if
(this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
}
else {
alert(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}
</script>
<body>
<div>
Account Name</div>
<div>
<input type="text" id="name" /></div>
<div>
Account Phone</div>
<div>
<input type="text" id="phone" /></div>
<div><input type="button" value="Create"
onclick="createAccount()"/></div>
</body>
</html>
Here I have used xmlHTTPRequest created by using Rest
Builder. You can get it from below:
(This is also utility created by jlattimer )
Create a Solution
Now next step is creating a solution. So just follow general
rules of CRM to create a solution as follow:
Step 1 − Navigate
to Settings → Solutions. Click New.
Step 2 − In the
window that follows, enter the following details and click Save and Close.
Display Name −
Sample Solution (This can be any name that you want).
Name − Will be
automatically set based on the Display Name. However, you can change this.
Publisher −
Default Publisher. Solution publisher provides a common customization prefix
and option value prefix. Defining a solution publisher controls how your
managed solutions can be updated once distributed. However, for this example
and for most of the general cases, you can set this as Default Publisher.
Version − Specify
a version with the following format: major.minor.build.revision. For example:
1.0.0.0.
Add Components to your solution
By default, every
solution is added as an unmanaged solution. Once a solution is added, you can
add solution components by creating them in the context of this solution or by
adding the existing components from other solutions. For example, you can
create new entities, forms, etc. in the context of this new solution.
Now it’s our turn to add components we may require. I just
need “Account” entity so I will add this in here.
Add Web Resource
Create a HTML Web resource in this solution and paste the
code we had in very first step. I would name it as “Create Account”.
In “Text Editor” paste content from very first step (or you
can just upload any HTML page from “Choose File”)
Add Configuration Page
Now here comes the final step. You need to add created Web
resource as configuration page. So just navigate to “Information” in solution
and add “Create Account” as configuration page:
Don’t forget to Save
and Publish your customizations.
Export solution as Managed
Now its turn to make our solution as managed so that no one
can modify it. So one simple step for this is just export solution as managed:
Import it anywhere
Now your own utility for CRM is ready. Use it and let others
use it by simply importing it in their CRM J
Happy CRMing J
Regards
Preeti Sharma
No comments:
Post a Comment