Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to set Value of Field on click of button

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi experts, 

I've created a button on ribbon workbench and I have a single line of text field on my case form called new_timer

I have added a javascript action on my button to check if the field is empty and also set the value of the field to "Inactive" onclick. 

Im using the following code but it doesn't seem to be working:

function CheckValue() 
{
        var phoneNo = Xrm.Page.getAttribute('new_timer').getValue();
        if (phoneNo != null)
            return true;
        else
            return false;
setValue();
}

function setValue()
{
Xrm.Page.getAttribute("phoneNo").setValue(Inactive);

}


*This post is locked for comments

  • How to set Value of Field on click of button
    1. //Try this-> (Updated MS CRM V.9.2) Hope it will be help full for you, Thank You.                            
    2.  function CheckValue(primaryContext)                                                               
    3.  {
    4.     try{
    5.   var phoneNo = primaryContext.getAttribute("new_timer").getValue();                       
    6.  
    7.   if (phoneNo != null)
    8.  
    9.     primaryContext.getAttribute("phoneNo").setValue(Inactive);                                 
    10.  
    11. }catch(ex){
    12.          console.log("Exception Catch:" + ex.message);                           
    13. }

    14. }






  • Anand Kumar M Profile Picture
    Anand Kumar M 120 on at
    RE: How to set Value of Field on click of button

    You have to call the setValue() before return statement & as others suggested the value "Inactive" should be enclosed in double quotes.  This  should solve the problem

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set Value of Field on click of button

    I tried my code with only the second function and it works. But when I call the second function from the first function, it doesnt work.

  • Darshik Profile Picture
    Darshik 295 on at
    RE: How to set Value of Field on click of button

    Hi,

    In the same replace the attribute name with your field name.

    function CheckValue()

    {

           var phoneNo = Xrm.Page.getAttribute('new_timer').getValue();

           if (phoneNo != null)

               Xrm.Page.getAttribute(Attribute).setValue("Inactive");

    }

  • Darshik Profile Picture
    Darshik 295 on at
    RE: How to set Value of Field on click of button

    Hi,

    try this

    function CheckValue()

    {

           var phoneNo = Xrm.Page.getAttribute('new_timer').getValue();

           if (phoneNo != null)

               Xrm.Page.getAttribute("phoneNo").setValue("Inactive");

    }

  • Suggested answer
    gdas Profile Picture
    gdas 50,087 on at
    RE: How to set Value of Field on click of button

    I found there is  wrong in your code - Try with  below code

    function CheckValue() 
    {
            var phoneNo = Xrm.Page.getAttribute("new_timer").getValue();
            if (phoneNo != null)
                return true;
            else
                return false;
    setValue();
    }
    
    function setValue()
    {
    Xrm.Page.getAttribute("phoneNo").setValue("Inactive");  /// You need to write inside double quote 
    
    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to set Value of Field on click of button

    Hi Darshik and Goutam,

    Yeap it a single line of text field. I tried that and its still not working.

    Thanks,

    Jon

  • Verified answer
    gdas Profile Picture
    gdas 50,087 on at
    RE: How to set Value of Field on click of button

    What type of field you are using?

    If its single line text then please use below code.

    Xrm.Page.getAttribute("fieldName").setValue("Any value"");

    Hope this helps.

    Mark as answer if its answer your question.

  • Verified answer
    Darshik Profile Picture
    Darshik 295 on at
    RE: How to set Value of Field on click of button

    Hi ,

    Set the value in the field as below format.

    Xrm.Page.getAttribute("phoneNo").setValue("Inactive");

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,784 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,476 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans