Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Help, Script no longer works after unified Interface Value should be of type: boolean error

Posted on by 5

Hi everyone, I hope you are all well. Our Dynamics 365 CRM just updated to the new unified platform and now one of the scripts that used to run flawlessly for the last 5 years no longer works.

I have a simple cost calculator setup in our opportunity screens that calculates sell price or Gross profit margin based on a selection the user makes.

When you execute the script the error Value should be of type: boolean pops up as an error.

I didn't write the script, it was setup years ago and I have no idea what to do to fix this issue.

Below is a copy of the script that runs. Can anyone help? Much appreciated!

function CalculateRevenue(button,calculation,costprice,sellprice,gpmpercent) {
Xrm.Page.data.entity.save();
var recalculate = Xrm.Page.data.entity.attributes.get(button);
recalculate.setValue(0);
var cost = Xrm.Page.data.entity.attributes.get(costprice).getValue();
var calc = Xrm.Page.data.entity.attributes.get(calculation).getValue();
if (calc > 0) {
var revenue = Xrm.Page.data.entity.attributes.get(sellprice);
var gpm = Xrm.Page.data.entity.attributes.get(gpmpercent).getValue();
revenue.setValue(0);
if (gpm < 99.99) {
revenue.setValue(cost/(1-(gpm*.01)));
}
else {
alert ("*** to set GPM to 100% set COST to Kinetix to 0");
}
}
if (calc < 1) {
var gpm = Xrm.Page.data.entity.attributes.get(gpmpercent);
var revenue = Xrm.Page.data.entity.attributes.get(sellprice).getValue();
gpm.setValue(0);
if (cost > revenue) {
alert ("***ERROR COST to kinetix is greater than SELL PRICE");
}
else {
gpm.setValue(((revenue-cost)/revenue) *100);
}
}
}

  • Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Help, Script no longer works after unified Interface Value should be of type: boolean error

    As you wish Joe, but doing it now would mitigate a mid/long-term risk with the current script

  • Joe Muscella Profile Picture
    Joe Muscella 5 on at
    RE: Help, Script no longer works after unified Interface Value should be of type: boolean error

    Hi Henry, Thanks for the quick response! I haven't tried this out yet as the above answer from Leah fixed my problem. If I run into issues I will give your answer a try.

    Thank you!

    Joe Muscella

  • Suggested answer
    Joe Muscella Profile Picture
    Joe Muscella 5 on at
    RE: Help, Script no longer works after unified Interface Value should be of type: boolean error

    Leah,

    Thanks so much , this worked perfectly! I really appreciate your quick response!

    Joe Muscella

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,237 on at
    RE: Help, Script no longer works after unified Interface Value should be of type: boolean error

    Hello Joe -

    There are other issues in your script that will need refactoring, such as the use of Xrm.Page that is deprecated (or else this could break at a later point in time).
    We have created an update of your code, can you try to use it instead?

    function CalculateRevenue(executionContext, button, calculation, costprice, sellprice, gpmpercent) {
        var formContext = executionContext.getFormContext();
        formContext.data.save().then(
            function () {
                formContext.getAttribute(button).setValue(false);
                var cost = formContext.getAttribute(costprice).getValue();
                var calc = formContext.getAttribute(calculation).getValue();
                
                if (calc > 0) {
                    var revenueAttr = formContext.getAttribute(sellprice);
                    var gpmAttr = formContext.getAttribute(gpmpercent).getValue();
                    revenueAttr.setValue(0);
                    if (gpmAttr < 99.99) {
                        revenueAttr.setValue(cost / (1 - (gpmAttr * .01)));
                    }
                    else {
                        Xrm.Navigation.openAlertDialog({
                            title: "Revenue calculation",
                            text: "*** to set GPM to 100% set COST to Kinetix to 0"
                        });
                    }
                }
                else if (calc < 1) {
                    var gpmAttr = formContext.getAttribute(gpmpercent);
                    var revenue = formContext.getAttribute(sellprice).getValue();
                    gpmAttr.setValue(0);
                    if (cost > revenue) {
                        Xrm.Navigation.openAlertDialog({
                            title: "Revenue calculation",
                            text: "***ERROR COST to kinetix is greater than SELL PRICE"
                        });
                    }
                    else {
                        gpmAttr.setValue(((revenue - cost) / revenue) * 100);
                    }
                }
            },
            function (error) {
                Xrm.Navigation.openErrorDialog(error);
            }
        );
    }

    Also, please make sure that the context is passed to your form function, in the Event Handlers

    pastedimage1611049003797v1.png

    Henry

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Help, Script no longer works after unified Interface Value should be of type: boolean error

    Hi Joe,

    The Boolean type error appears in the field that data type is ‘Twop options’,

    The D365 legacy Xrm.Page field used to accept 0 for the false value,but UCI require false instead of 0 (zero).

    So you need change js code:

    recalculate.setValue(0); should changed to recalculate.setValue(false);

    also, you can check all fields that exsit in js, if the data type is two options, you need use ture/false to set it’s value.

    Regards,

    Leah Ju

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

New! Quick response templates⚡

Save time with the new custom templates!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,228 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,056 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans