Power Platform - Apps - Automate - SharePoint
Pages
Applications basées sur un modèle (model driven apps)

icon picker
Ressources JavaScript


Codes JavaScript de base
Code
Contexte
var Example = window.Example || {};
(function () {
var varGlobal = 1;
this.MaFonction = function (executionContext) {
}
}).call(Example);
Squelette d’un script.
var formContext = executionContext.getFormContext();
Dans une fonction, pour manipuler ensuite le formulaire actif
var valeur = formContext.getAttribute("abc_nomchamp").getValue();
Récupère la valeur d’un champ du formulaire.
if (valeur && typeof valeur === "object" && valeur.hasOwnProperty("text"))
{
var test = valeur.text
}
Pour récupérer la valeur “text” d’un champ (hors champ de recherche)
if (Array.isArray(valeur) && valeur.length > 0 && valeur[0].name) {
var test = valeur[0].name;
}
Champ de recherche. 3 propriétés : id, name et entityType.
var arraySocieteID = [{
id: result._abc_societeid_value,
name: result["_abe_societeid_value@OData.Community.Display.V1.FormattedValue"],
entityType: "abe_societe"
}];

formContext.getAttribute("abe_societeid").setValue(arraySocieteID)
Compose un champ de recherche puis l’affecte à un champ
Xrm.WebApi.retrieveRecord("entity", "id").then(
function success(result) {
var societeID = result._abc_societeid_value;
},
function (error) {
console.error(error.message);
}
);
Recherche un enregistrement dans une entité.
var lookupValue = formContext.getAttribute("abc_table_id").getValue();
if (lookupValue && lookupValue.length > 0) {
table_id = lookupValue[0].id.replace(/[{}]/g,"");
var parentEntityName = table_id[0].entityType;
}

Récupère le GUID d’un champ de type Recherche et son entity.
Xrm.Navigation.openAlertDialog({ text: le_texte });
Affiche un messaage
There are no rows in this table

Affiche champs et valeurs d’un formulaire

function afficherChampsEtValeurs(executionContext) {
var formContext = executionContext.getFormContext();
var attributs = formContext.data.entity.attributes.get();
var resultats = [];
for (var i = 0; i < attributs.length; i++) {
var attribut = attributs[i];
var nomChamp = attribut.getName();
var valeur = attribut.getValue();
// Gestion des lookups et valeurs complexes
if (Array.isArray(valeur) && valeur.length > 0 && valeur[0].name) {
valeur = valeur[0].name;
} else if (valeur && typeof valeur === "object" && valeur.hasOwnProperty("text")) {
valeur = valeur.text;
}
resultats.push(nomChamp + " : " + valeur);
}
// Affichage dans une fenêtre de message (limité à 4000 caractères)
Xrm.Navigation.openAlertDialog({
text: resultats.join('\n')
});
}

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.