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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Auto-populate required name field

(0) ShareShare
ReportReport
Posted on by

I have been trying the below code without any success.  Then schema name of the field is 'cei_name'.

Any thoughts on what I'm missing here or alternate code recommendations?  Thanks

[code lang=”js”]

function name()

{ var now = new Date();

if (crmForm.all.cei_name.DataValue==null)

{

crmForm.all.cei_name.DataValue=(now.toString());

}

}

[/code]

*This post is locked for comments

I have the same question (0)
  • ScottDurow Profile Picture
    23 on at

    You should use:

    var nameAttribute=Xrm.Page.getAttribute('cei_name');

    var currentValue = nameAttribute.getValue();

    if ( currentValue== null || currentValue == '')

    nameAttribute.setValue(now.toString());

  • Community Member Profile Picture
    on at

    Thanks Scott.  Here is the code I'm using (yours that I had to alter a bit to get working).  I need to format this date to a YYYY-MM as I am getting an int.  Any thoughts on that?

    function namefill()

    { var nameAttribute = Xrm.Page.getAttribute("cei_name");

     var currentValue = nameAttribute.getValue();
    {
     if ( currentValue == null || currentValue == '')
     
     nameAttribute.setValue(Date.now.toString());
     
    }

    }

  • Kalim Khan Profile Picture
    25 on at

    Are you trying to set he current time? Try below  

      var currentdate = new Date().toLocaleTimeString().toString();

       nameAttribute.setValue(currentdate);

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at

    Hi,

    Get the value of a Date field.

    Please refer the below link:

    intersection3.com/.../dynamics-crm-2015-javascript-reference

  • Community Member Profile Picture
    on at

    I am trying to take the string value I generated by the code above (this works, it writes to he cei_name field) and convert that to a YYYY-MM format by adding to that code.

  • Verified answer
    Community Member Profile Picture
    on at

    This works:

    function namefill()

    { var nameAttribute = Xrm.Page.getAttribute("cei_name");

    var currentValue = nameAttribute.getValue();

    {

    if ( currentValue == null || currentValue == '')

    var today = new Date();

    var mm = today.getMonth()+1;

    var yyyy = today.getFullYear();

    nameAttribute.setValue(yyyy + "-" + mm)

    }

    }

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans