locked
Can I use fixed value in a text field? RRS feed

  • Question

  • Hi,

    I want to have a fixed value say '1500' in a read only field. How can I do that?

    It will be helpful if you let me know how to do it step by step.

    Thanks,

    Venkat

    Wednesday, July 18, 2012 6:55 AM

Answers

  • Hi .. 

    what type of field you are trying to set the value , is it text field or  (whole number field  & currency Field).

    If you are setting a value for text field use bellow code..

    function Setvalue()
     { 
     var Name = Xrm.Page.data.entity.attributes.get("new_value"); 
    Name.setValue("555");
    }

    ----------------------------------------------------------------------------------------------------------------------------

    If you are setting a value for (whole number field  & currency Field). use bellow code..

    function Setvalue()
     { 
    Xrm.Page.getAttribute("new_value").setValue(555);
    }

    For Java Script Basic Reference Refer Bellow Link

    http://gtcrm.wordpress.com/2011/03/16/jscript-reference-for-microsoft-crm-2011/


    • Edited by Parthiban.T Tuesday, July 31, 2012 5:20 AM
    • Marked as answer by Venkat1986 Friday, August 31, 2012 1:53 AM
    Thursday, July 19, 2012 11:07 AM

All replies

  • Hi Venkat,

      function setvalue()

    {

               Xrm.Page.data.entity.attributes.get("YourFieldname").SetValue(1500);  

          Xrm.Page.getAttribute("YourFieldname").setSubmitMode("always");

            

    }

    call this java script  function in form OnSave Event. before that set field as readonly

    Wednesday, July 18, 2012 7:11 AM
  • Gugan is right..

    open the entity and in customize tab select form

    and in form properties add a new a new form library

    and add a new webresource and type as jscript

    use text editor and put the above code and give a name and save it

    and in the form on load event give the function name and save and publish..

    thats all the values will be populated when ever a record is opened.


    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful. Regards, Hari.

    Wednesday, July 18, 2012 12:02 PM
  • @gugan: It is not working :(
    • Edited by Venkat1986 Wednesday, July 18, 2012 11:23 PM
    Wednesday, July 18, 2012 11:15 PM
  • @Irah: No. It is not working :(



    • Edited by Venkat1986 Wednesday, July 18, 2012 11:33 PM
    Wednesday, July 18, 2012 11:15 PM
  • hi venkat,

    Try this,

    In the jscript use your fields schema name and not the display name, for custom attribute schemaname will be like "new_xxxxxx".

      Xrm.Page.getAttribute("CRMFieldSchemaName").setValue(1500);


    If my response answered your question, please "mark the response as an answer" and also "vote as helpful". Regards, Hari. www.crm2011byhari.blogspot.com

    Thursday, July 19, 2012 5:14 AM
  • There is a few basics of javascript for crm 2011 in the below link..

    http://crmbusiness.wordpress.com/2011/02/17/crm-2011-javascript-xrm-page-basics/

    will be usefull.


    If my response answered your question, please "mark the response as an answer" and also "vote as helpful". Regards, Hari. www.crm2011byhari.blogspot.com

    Thursday, July 19, 2012 5:15 AM
  • Hi .. 

    what type of field you are trying to set the value , is it text field or  (whole number field  & currency Field).

    If you are setting a value for text field use bellow code..

    function Setvalue()
     { 
     var Name = Xrm.Page.data.entity.attributes.get("new_value"); 
    Name.setValue("555");
    }

    ----------------------------------------------------------------------------------------------------------------------------

    If you are setting a value for (whole number field  & currency Field). use bellow code..

    function Setvalue()
     { 
    Xrm.Page.getAttribute("new_value").setValue(555);
    }

    For Java Script Basic Reference Refer Bellow Link

    http://gtcrm.wordpress.com/2011/03/16/jscript-reference-for-microsoft-crm-2011/


    • Edited by Parthiban.T Tuesday, July 31, 2012 5:20 AM
    • Marked as answer by Venkat1986 Friday, August 31, 2012 1:53 AM
    Thursday, July 19, 2012 11:07 AM