web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to set Value of Field on click of button

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Verified answer
    Darshik Profile Picture
    295 on at

    Hi ,

    Set the value in the field as below format.

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

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

  • Community Member Profile Picture
    on at

    Hi Darshik and Goutam,

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

    Thanks,

    Jon

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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 
    
    }

  • Darshik Profile Picture
    295 on at

    Hi,

    try this

    function CheckValue()

    {

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

           if (phoneNo != null)

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

    }

  • Darshik Profile Picture
    295 on at

    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");

    }

  • Community Member Profile Picture
    on at

    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.

  • Anand Kumar M Profile Picture
    122 on at

    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
    2 on at
    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. }






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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans