Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

having issue with submitting data from a read only field, to a read only field using js

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

ok so I am doing a couple calculations using javascript and passing the total in a READ ONLY total field, which works fine....   example: mileage * rate = total mileage cost

I do it again, with another set of fields and again I pass the total to a read only field... which works fine...

example:  service hours * hourly rate = total service cost

So at this point I have a 'total mileage cost' and a 'total service cost' numbers...(both total fields again are READ ONLY)..

I want to calculate 'total mileage cost' + 'total service cost' and output the sum number into a 'total expense' field which is READ ONLY...

If I put my javascript under a field that IS NOT read only - it grabs the numbers and populates the 'total expense' field, however if I change service hours from 2 to (any number) 3, that triggers some js which recalculates total service cost, (HERE IS THE PROBLEM), however it does not update 'total expense' ...

I want to be able to stick this code under total service cost and total mileage cost and it calculate the total expense and recalculates total expense anytime either of those values change.....

Thanks for the help in advance.

not sure if this is necessary but here is my code, 

function caltotalproservicecost_onchange() {

var RateTotal = Xrm.Page.getAttribute("new_ratetotal").getValue();
var TravelTotal = Xrm.Page.getAttribute("new_totaltravel").getValue();

var TotalPS = (RateTotal + TravelTotal); 
Xrm.Page.getAttribute("new_totalps").setValue(TotalPS);

}

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: having issue with submitting data from a read only field, to a read only field using js

    Thanks Raj, I checked the link and I appreciate the information greatly, and will try this out!

    I misread it the first time, I didn't catch the 'make second field NOT visible on form'

  • Verified answer
    RE: having issue with submitting data from a read only field, to a read only field using js

    Hi Adam,

    Based on read about some of the articles, Need to set one field as readonly another one as non-read only. Walkthrough the following article. you have an idea:

    community.dynamics.com/.../tip-save-read-only-field-values-when-value-set-by-business-rule

    Hope this helps.

    Regards,

    R.Rajkumar

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: having issue with submitting data from a read only field, to a read only field using js

    Thanks I tried that already, no dice.

    data flow:

    data submitted from a non read only field to a read only field  - works fine

    data submitted from a read only field does not work at all - it won't go to a read only or non read only field... I'm guessing it's some property being disabled when making the SENDING (field passing the information) field read only, which won't allow it to send data or set data or update data into another field?

  • RE: having issue with submitting data from a read only field, to a read only field using js

    refer this thread:

    social.microsoft.com/.../read-only-field-isnt-saved-after-update-via-jscript

  • RE: having issue with submitting data from a read only field, to a read only field using js

    Hi Adam,

    try this:

    function caltotalproservicecost_onchange() {

    var RateTotal = Xrm.Page.getAttribute("new_ratetotal").getValue();

    var TravelTotal = Xrm.Page.getAttribute("new_totaltravel").getValue();

    var TotalPS = (RateTotal + TravelTotal);

    Xrm.Page.getAttribute("new_totalps").setValue(TotalPS);

    Xrm.Page.getAttribute("new_totalps").setSubmitMode("always");//final update

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: having issue with submitting data from a read only field, to a read only field using js

    what I am trying to do here is simply say when service total (read only field) and travel total (read only field) contain data, sum the two fields up and put them in another field called total expense (read only field) - the problem is that when I set the js code to trigger on the real only fields, even though the fields contain data, the data or value will not transfer to the total expense field.

    I know read only fields can accept data or a value and updated values if a field value which makes up the calculation is changed, it updates.. BUT that is from a field which is NOT read only... So something's going on when placing js code under a read only field, when it updates the js doesn't fire in order to update the total expenses field... I hope that makes more sense,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: having issue with submitting data from a read only field, to a read only field using js

    hey Raj, that's awesome I can actually use this somewhere else I need it but for this example there are no option sets here, every field is an individual field, it's the read only thing that is kicking my butt. Thanks for reply though.

  • Suggested answer
    RE: having issue with submitting data from a read only field, to a read only field using js

    Hi Adam,

    Try this:

    function caltotalproservicecost_onchange() {

       var servicecost = Xrm.Page.getAttribute("youroptionsetfieldname").getOptions();//here you put your optionset field,

        var RateTotal = Xrm.Page.getAttribute("new_ratetotal").getValue();

        var TravelTotal = Xrm.Page.getAttribute("new_totaltravel").getValue();

        if (servicecost == 3) {

            var TotalPS = (RateTotal + TravelTotal);

            Xrm.Page.getAttribute("new_totalps").setValue(TotalPS);

        }

        else {

            //put your logic

        }

    }

    Call this function on your optionset onchangeevent

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,468 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans