Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Changing field values on the fly

Posted on by 550

Hi together,

Unfortunately I'm not yet so familiar with JavaScript and XRM. So I got one question.

I got two costum fields in Opportunity - "Project Size In Qm" and "Project Size In SQFT".

So now my aim is, that if one user is leaving a field after typing in a value, the other field should get the conversion value directly and automatically.

At the moment the values change, but after one value was set, saved and the page was reloaded.

Can somebody maybe help me with this? 

This would be awesome

Best regards 

Mick

P.S.: maybe I will change the conditions again.

function changeValueQmSqft() {

      
    var valueFieldSqft = Xrm.Page.getAttribute("projektgre_in_qm").getValue();
    var valueFieldQm = Xrm.Page.getAttribute("projektgre_in_m2").getValue();

    try {
        if (valueFieldQm > valueFieldSqft) {
           
            valueFieldQm = valueFieldQm * 10.76390578220045;
            Xrm.Page.getAttribute("projektgre_in_qm").setValue(valueFieldQm);
        }
        else {
            
            valueFieldSqft = valueFieldSqft * 0.092903;
            Xrm.Page.getAttribute("projektgre_in_m2").setValue(valueFieldSqft);
        }

        } catch (e) {

        }
    
}

*This post is locked for comments

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    Hi Prem,

    thank you for your information.

    But as I wanna learn to write codes, I wanna chose the hard way ;)

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    Sorry, now I got it. I didn't know that I can put a code in the field properties. I gonna try this.

    Many thanks for your help.

  • Suggested answer
    Prem27 Profile Picture
    Prem27 370 on at
    RE: Changing field values on the fly

    Hi Mick,

    You can use CRM  Calculated fields for conversion purposes.

    Saves the effort of writing and registering custom code.

    Regards

    Prem Prakash

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Changing field values on the fly

    Instead of OnSave- Change it to Onchange of field as I said earlier, Double click field->Field Properties->Event->Add your method there, you can add your method in both fields onchange. Save and Publish.

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    Aaaaaaaaaaaaaaaah, okay!

    I changed it to "OnSave".

    So the values change, when I save the page.  

    Sorry for another question as I am a Xrm-newbie. But how do I use the onChange-trigger?

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    In the Form Properties/Event Handler? Onload.

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Changing field values on the fly

    Ok, Where are you calling this script currently ?? Onload/Onsave/OChange ??

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    Thanks Ganesh,

    exactly. But I wasn't sure, how to use it. That's why I had to ask.

    I will definitely change the conditions. I just wanted to get it work quick and improve later.

  • Mick_4711 Profile Picture
    Mick_4711 550 on at
    RE: Changing field values on the fly

    Thanks Himbap,

    yes, I tried that as a business rule. But it wasn't possible to multiply with a float as I have to; just with a decimal number.

  • Verified answer
    Ganesh Chowhan Profile Picture
    Ganesh Chowhan 160 on at
    RE: Changing field values on the fly

    Hi,

    I believe you are trying to invoke the method from both field onChange event not on for onLoad, right? If you trigger method from onLoad/ OnSave event it will work only when record/ or form opened/ loaded/ Saved. Try triggering the method onChange of the field.

    Also you may add some null/ blank/ undefined check condition in your script to avoid any scripting error on arithmetic operation.

    Thank you!

    Ganesh.

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!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans