locked
Function to set a picklist value if it is null on save - CRM 4 RRS feed

  • Question

  • I have several picklist fields and I want to use their values in a calculation. To do this I need to check first if they are null or N/A (value = '999') and if so use a zero in the calculation. I think the code below would work if '0' was an option in my picklist, but it's not.

    function settermzero(termfield)

    {

        if (crmForm.all[termfield].DataValue == null || crmForm.all[termfield].DataValue  == '999')

        {

           crmForm.all[termfield].DataValue = '0';

        }

    }

    settermzero('myfieldname');

    I have been trying to create a var called myfieldname in the function and set that to 0. That would then get used in a calculation outside the function instead of parseInt(crmForm.all.myfieldname.DataValue), but no luck so far.

    Can anyone tell me how to do this please?

    Monday, October 22, 2012 12:52 PM

Answers

  • I have got this to work, though I didn't find a way to create the variable within the function.

    function settermzero(termfield)
    {
        if (crmForm.all[termfield].DataValue == null ||
            crmForm.all[termfield].DataValue  == '999')
            return 0;
       
        else return parseInt(crmForm.all[termfield].DataValue);
    }

    myfieldname = settermzero('myfieldname');

    • Marked as answer by STHook Tuesday, October 23, 2012 9:58 AM
    Tuesday, October 23, 2012 9:58 AM

All replies

  • Hi,

    doesn't this work?

    function settermzero(termfield)
    
    {
    
        if (crmForm.all[termfield].DataValue == null || crmForm.all[termfield].DataValue  == '999')
    
        {
    
           myCalculation(0);
    
        }
    
    }
    
    function myCalculation(termField)
    {
      \\do some calculation
    }

    Greetings,

    Pavlos


    Please mark this reply as an answer and vote it as helpful if it helps you find a resolution to your problem.
    View my latest gallery contribution here.
    Visit my blog here.

    Monday, October 22, 2012 1:06 PM
  • hi

    try this

    function settermzero(termfield)
     
    {
     
        if (crmForm.all[termfield].DataValue == null || crmForm.all[termfield].DataValue  == '999')
     
        {
     
           crmForm.all[termfield].DataValue = 0;
    //0 is your picklist value
    
     
        }
     
    }




    • Proposed as answer by Riaz Usmani Monday, October 22, 2012 1:33 PM
    • Unproposed as answer by STHook Monday, October 22, 2012 1:48 PM
    • Edited by Riaz Usmani Tuesday, October 23, 2012 6:00 AM
    Monday, October 22, 2012 1:30 PM
  • Hi,

    First I will suggest you to go through this link : http://osubrenden.wordpress.com/2010/05/13/working-with-crm-4-0-data-types-and-form-controls/

    if you want to set value then below code should work fine

    crmForm.all[termfield].DataValue = 0; //it will set text in index 0

    and if you want to fetch selected text index

    var value=parseInt(crmForm.all[termfield].DataValue);

    HTH


    Contact Me
    Follow me on Twitter
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Monday, October 22, 2012 2:59 PM
    Moderator
  • I have got this to work, though I didn't find a way to create the variable within the function.

    function settermzero(termfield)
    {
        if (crmForm.all[termfield].DataValue == null ||
            crmForm.all[termfield].DataValue  == '999')
            return 0;
       
        else return parseInt(crmForm.all[termfield].DataValue);
    }

    myfieldname = settermzero('myfieldname');

    • Marked as answer by STHook Tuesday, October 23, 2012 9:58 AM
    Tuesday, October 23, 2012 9:58 AM