Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function checkAssetFinancialStanding(executionContext) {
- var formContext = executionContext.getFormContext();
- var createBookingField = formContext.getControl("hha_bookingcreate");
- var financialstanding;
- var customerAsset = formContext.getAttribute("msdyn_customerasset").getValue()
- var assetId = customerAsset[0].id;
- console.log("Asset Guid : " + assetId);
- SDK.REST.retrieveRecord(
- assetId,
- "msdyn_customerasset",
- null, null,
- financialstanding = getAssetDetails,
- errorHandler
- );
- if (financialstanding !== "good standing") {
- var actionCollection = {
- message: "Please set value of the Bonus Potential field",
- actions: null
- };
- createBookingField.addNotification({
- messages: ["Set Bonus Potential"],
- notificationLevel: "RECOMMENDATION",
- uniqueId: "001",
- actions: [actionCollection]
- });
- } else {
- createBookingField.clearNotification("001");
- }
- }
- function getAssetDetails(asset) {
- console.log("Asset name : " + asset.msdyn_name);
- console.log("Financial Standing : " + asset.hha_financialstanding);
- var createBookingField = formContext.getControl("hha_bookingcreate");
- var optionSet = getFinancialStandingOptions("msdyn_customerasset", "hha_financialstanding", asset.hha_financialstanding);
- //var financialstanding = optionSet.find(data => data.value === asset.hha_financialstanding);
- var fsOption = optionSet.find(function (element) {
- return element.value === asset.hha_financialstanding.value;
- });
- return fsOption.Label.LocalizedLabels[0].Label;
- }
- function getFinancialStandingOptions(entityName, fieldName, optionId) {
- var optionSet
- var qryStr = "/api/data/v8.2/EntityDefinitions(LogicalName='" + entityName + "')/Attributes/Microsoft.Dynamics.CRM.PicklistAttributeMetadata?$select=LogicalName&$filter=LogicalName eq '" + fieldName + "'&$expand=OptionSet,GlobalOptionSet"
- var req = new XMLHttpRequest();
- req.open("GET", Xrm.Page.context.getClientUrl() + qryStr, false);
- 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
- req.onreadystatechange = function () {
- if (this.readyState === 4) {
- req.onreadystatechange = null;
- if (this.status === 200) {
- var results = JSON.parse(this.response);
- if (results === undefined || results.length == 0) {
- console.log("Option '" + fieldName + "' Set Not Found in Entity '" + entityName + "'")
- } else {
- optionSet = results.value[0].GlobalOptionSet.Options
- }
- } else {
- console.log(this.statusText)
- }
- }
- };
- req.send();
- return optionSet;
- }
- function errorHandler(error) {
- console.log(error.message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement