- 18 Nov 2024
- 11 Minutes à lire
- SombreLumière
- PDF
Exemple de code HTML
- Mis à jour le 18 Nov 2024
- 11 Minutes à lire
- SombreLumière
- PDF
Vous devrez peut-être ajuster les chemins d’accès des src
attributs dans les <script>
balises et <img>
de l’exemple suivant pour qu’ils reflètent l’emplacement de la ressource associée.
Par exemple, supposons qu’un utilisateur ait enregistré la ressource /WebResources/new_/something.htm
. Dans ce cas, les chemins relatifs nécessiteraient l’insertion d’un extra ../
avant chaque référence. Ainsi, la première référence dans l’exemple de code ci-dessous deviendrait :
<script src="../../ClientGlobalContext.js.aspx" type="text/javascript"></script>
Nous recommandons aux intégrateurs de privilégier les chemins relatifs aux chemins fixes ou absolus.
L’exemple suivant utilise une gestion minimale des erreurs. Chaque intégrateur doit s’assurer que le code qu’il met en œuvre répond aux normes de gestion des erreurs qu’il souhaite appliquer.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script src="../esl_/scripts/jquery.js" type="text/javascript"></script>
<script src="../esl_/scripts/jquery_ui.js" type="text/javascript"></script>
<script src="../esl_/scripts/json.js" type="text/javascript"></script>
<script src="../esl_/scripts/XrmServiceToolkit.js" type="text/javascript"></script>
<style>
ul {
margin: -8px 0 0 0;
}
li {
float: left;
display: inline;
margin-left: 5px;
}
</style>
</head>
<body>
<div>
<ul>
<li><button id="btnCreate"><img src="../esl_/images/PackageCreateIcon.png" height="14" alt="Create Package" /><span>Create</span></button></li>
<li><button id="btnCreate2"><img src="../esl_/images/PackageCreateIcon.png" height="14" alt="Create Package with template" /><span>Create2</span></button></li>
</ul>
</div>
<script type="text/javascript">
$(function () {
"use strict";
function get (key) {
var attr = parent.Xrm.Page.getAttribute(key);
return attr.getValue();
};
function failedCall(error) {
try {
parent.Xrm.Utility.alertDialog(message);
} catch (e) {
alert(error.message);
}
}
function createOnCrm (item, entitySet, callback) {
XrmServiceToolkit.Rest.Create(item,
entitySet,
function (result1) {
if (callback)
callback(result1);
},
failedCall,
false);
}
function createSoapOnCrm (be, callback) {
var result1 = XrmServiceToolkit.Soap.Create(be);
if (callback)
callback(result1);
}
function addSignerToPackage (id, s, callback) {
XrmServiceToolkit.Rest.Associate(
id,
"esl_packageSet",
s,
"esl_signerSet",
"esl_package_signer ",
function (resp) {
callback(resp);
},
failedCall,
false);
}
function getTemplateByName (name) {
var result1 = {
Id: "00000000-0000-0000-000000000000",
Name: "",
LogicalName: "esl_template"
};
XrmServiceToolkit.Rest.RetrieveMultiple(
"esl_templateSet",
"?$top=1&$select=esl_templateId,esl_name&$filter=esl_name eq '" + name + "'",
function (result) {
result1.Id = result[0].esl_templateId;
result1.Name = result[0].esl_name;
},
failedCall,
function () {},
false);
return result1;
}
function getPackageSimple (name) {
var currentdate = new Date();
return {
esl_name: "test-" + name,
esl_description: "test " + name + " " + currentdate.toLocaleTimeString(),
esl_lookupobjecttype: parent.Xrm.Page.context.getQueryStringParameters().etc,
esl_loopkuprecordguid: parent.Xrm.Page.data.entity.getId(),
esl_lookuprecordname: name,
esl_lookupentitytype: parent.Xrm.Page.data.entity.getEntityName(),
};
}
function getPackageWithTemplate(name, templatename) {
var currentdate = new Date();
var templateRef = getTemplateByName(templatename);
return {
esl_name: "test-" + name,
esl_description: "test " + name + " " + currentdate.toLocaleTimeString(),
esl_lookupobjecttype: parent.Xrm.Page.context.getQueryStringParameters().etc,
esl_loopkuprecordguid: parent.Xrm.Page.data.entity.getId(),
esl_lookuprecordname: name,
esl_lookupentitytype: parent.Xrm.Page.data.entity.getEntityName(),
esl_basedontemplate: templateRef,
};
}
function getPrimaryContact(callback) {
var primarycontactid = get("primarycontactid");
if (!primarycontactid) return null;
var contactRef = primarycontactid[0];
var be = new XrmServiceToolkit.Soap.BusinessEntity("esl_signer", null);
be.attributes.esl_name = "Signer1";
be.attributes.esl_signingorder = 2;
be.attributes.esl_contactid = {
id: contactRef.id,
logicalName: contactRef.entityType,
name: contactRef.name,
type: "EntityReference",
};
XrmServiceToolkit.Rest.Retrieve(
contactRef.id,
"ContactSet",
"EMailAddress1,FirstName,LastName,JobTitle,MobilePhone",
null, /*expand*/
function (resp) {
if (resp) {
be.attributes.esl_emailaddress = resp.EMailAddress1;
be.attributes.esl_firstname = resp.FirstName;
be.attributes.esl_lastname = resp.LastName;
be.attributes.esl_title = resp.JobTitle;
be.attributes.esl_smsphone = resp.MobilePhone;
}
callback(be);
},
failedCall,
false);
}
function openPackage (packageId) {
parent.Xrm.Utility.openEntityForm("esl_package", packageId);
}
function addSigner(contact, packageId, callback) {
if (contact == null) openPackage(packageId);
createSoapOnCrm(contact,
function (result2) {
addSignerToPackage(
packageId,
result2,
function () {
callback(packageId);
});
});
}
function createPackage(eslPackage) {
createOnCrm(eslPackage,
"esl_packageSet",
function(p) {
getPrimaryContact(
function(contact) {
addSigner(
contact,
p.esl_packageId,
function(id) {
openPackage(id);
});
});
});
}
$("#btnCreate").click(function () {
var p = getPackageSimple(get("name"));
try {
createPackage(p);
} catch (e) {
failedCall(e);
}
});
$("#btnCreate2").click(function () {
var p = getPackageWithTemplate(get("name"), "template01");
try {
createPackage(p);
} catch (e) {
failedCall(e);
}
});
});
</script>
</body>
</html>