1654772400
Dynamics 365 CRMでは、特定の要件について、レコードに存在するヘッダー値を取得する必要があります。フォームコンテキストで値を取得できます。例として、連絡先レコードのフォームコンテキストを使用して、所有者の値を取得しました。
ステップ1
次の図に示すように、必要な環境にログインして、必要なソリューション[この場合はカスタマイズソリューションに連絡]を選択します。
ステップ2
手順1の後、次の図に示すように、ソリューション内の連絡先Webリソースを選択し、[編集]をクリックします。
ステップ3
ステップ2の後、連絡先レコードのヘッダーフィールドに存在する値を取得するために使用される以下のコード
var headerownername;
if (formContext.getControl("header_ownerid") != null) {
headerownername = formContext.getControl("header_ownerid").getAttribute().getValue()[0].name;
}
ステップ4
手順3の後、上記のコードスニペットを関数内に保持し、連絡先テーブル(エンティティ)フォームのフォームロードイベントに登録すると、最終的なコードは次のようになります。
if (typeof(ContosoVaccination) == "undefined") {
var ContosoVaccination = {
__namespace: true
};
}
if (typeof(ContosoVaccination.Scripts) == "undefined") {
ContosoVaccination.Scripts = {
__namespace: true
};
}
ContosoVaccination.Scripts.ContactForm = {
handleOnLoad: function(executionContext) {
console.log('on load - contact form');
showDialog(executionContext);
},
__namespace: true
}
function showDialog(executionContext) {
let formContext = executionContext.getFormContext();
if (formContext !== null && formContext != 'undefined') {
var headerownername;
if (formContext.getControl("header_ownerid") != null) {
headerownername = formContext.getControl("header_ownerid").getAttribute().getValue()[0].name;
}
var confirmStrings = {
text: "Owner Details : " + headerownername,
title: "Header value",
confirmButtonLabel: "Yes",
cancelButtonLabel: "No"
};
var confirmOptions = {
height: 200,
width: 450
};
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(function(success) {
if (success.confirmed) console.log("Dialog closed using Yes button.");
else console.log("Dialog closed using No button or X.");
});
}
}
ステップ5
手順4の後、Webリソースを保存して公開し、すべてのカスタマイズを公開して、連絡先レコードを開き、次の図に示すように、ヘッダー値のタイトルと値を含むダイアログを確認します。
注
すべてのカスタマイズを公開し、JavaScript(js)ファイルをアップロードしてください。
このようにして、ヘッダー値Webresource(javascript)を簡単に取得できます。
このストーリーは、もともとhttps://www.c-sharpcorner.com/article/get-header-values-with-webresource-in-dynamics-crm/で公開されました。
1654772400
Dynamics 365 CRMでは、特定の要件について、レコードに存在するヘッダー値を取得する必要があります。フォームコンテキストで値を取得できます。例として、連絡先レコードのフォームコンテキストを使用して、所有者の値を取得しました。
ステップ1
次の図に示すように、必要な環境にログインして、必要なソリューション[この場合はカスタマイズソリューションに連絡]を選択します。
ステップ2
手順1の後、次の図に示すように、ソリューション内の連絡先Webリソースを選択し、[編集]をクリックします。
ステップ3
ステップ2の後、連絡先レコードのヘッダーフィールドに存在する値を取得するために使用される以下のコード
var headerownername;
if (formContext.getControl("header_ownerid") != null) {
headerownername = formContext.getControl("header_ownerid").getAttribute().getValue()[0].name;
}
ステップ4
手順3の後、上記のコードスニペットを関数内に保持し、連絡先テーブル(エンティティ)フォームのフォームロードイベントに登録すると、最終的なコードは次のようになります。
if (typeof(ContosoVaccination) == "undefined") {
var ContosoVaccination = {
__namespace: true
};
}
if (typeof(ContosoVaccination.Scripts) == "undefined") {
ContosoVaccination.Scripts = {
__namespace: true
};
}
ContosoVaccination.Scripts.ContactForm = {
handleOnLoad: function(executionContext) {
console.log('on load - contact form');
showDialog(executionContext);
},
__namespace: true
}
function showDialog(executionContext) {
let formContext = executionContext.getFormContext();
if (formContext !== null && formContext != 'undefined') {
var headerownername;
if (formContext.getControl("header_ownerid") != null) {
headerownername = formContext.getControl("header_ownerid").getAttribute().getValue()[0].name;
}
var confirmStrings = {
text: "Owner Details : " + headerownername,
title: "Header value",
confirmButtonLabel: "Yes",
cancelButtonLabel: "No"
};
var confirmOptions = {
height: 200,
width: 450
};
Xrm.Navigation.openConfirmDialog(confirmStrings, confirmOptions).then(function(success) {
if (success.confirmed) console.log("Dialog closed using Yes button.");
else console.log("Dialog closed using No button or X.");
});
}
}
ステップ5
手順4の後、Webリソースを保存して公開し、すべてのカスタマイズを公開して、連絡先レコードを開き、次の図に示すように、ヘッダー値のタイトルと値を含むダイアログを確認します。
注
すべてのカスタマイズを公開し、JavaScript(js)ファイルをアップロードしてください。
このようにして、ヘッダー値Webresource(javascript)を簡単に取得できます。
このストーリーは、もともとhttps://www.c-sharpcorner.com/article/get-header-values-with-webresource-in-dynamics-crm/で公開されました。