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)

Concatenate three fields on the same form and input them into a single field

(0) ShareShare
ReportReport
Posted on by

I am trying to take name + service calendar week + service date and concatenate them, then place them into the name field.

Here's my code - I am getting an onload event error, it may very well not be structured properly.

Thanks,

function concatriskcompliancefields_onload()

 var Name = Xrm.Page.getAttribute("new_name").getValue();
 var ServiceCalWeek = Xrm.Page.getAttribute("new_servicecalendarserviceweek").getValue();
 var ServiceDate = Xrm.Page.getAttribute("new_servicedate").getValue();

 Xrm.Page.getAttribute("new_name").setValue(Name + ServiceCalWeek + ServiceDate);
 Xrm.Page.getAttribute("new_name").setSubmitMode("always");

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Royal King Profile Picture
    27,686 on at

    You are missing open and close function parenthesis.Try with below code

    function concatriskcompliancefields_onload()

    {

    var Name = Xrm.Page.getAttribute("new_name").getValue();

    var ServiceCalWeek = Xrm.Page.getAttribute("new_servicecalendarserviceweek").getValue();

    var ServiceDate = Xrm.Page.getAttribute("new_servicedate").getValue();

    Xrm.Page.getAttribute("new_name").setValue(Name + ServiceCalWeek + ServiceDate);

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

    }

  • Aileen Gusni Profile Picture
    44,524 on at

    Adam,

    Beside you miss the bracket, I think you also need to check whether your attribute got data or not.

    Example here for concatenation

    businesswithcrm.wordpress.com/.../concatenation-of-two-crm-fields-using-j-script

    Hope this helps.

    THanks.

  • khoait Profile Picture
    450 on at

    Hi Adam,

    You should check the value is null or not before concatnation as Aileen said.

    I'll also check whether the getAttribute('attributeName') is null or not. Safety first :)

    Hope this helps.

  • Suggested answer
    Community Member Profile Picture
    on at

    Try this code once

    var Name = "";

    Name=Xrm.Page.getAttribute("new_name").getValue();

    var ServiceCalWeek = "";

    ServiceCalWeek=Xrm.Page.getAttribute("new_servicecalendarserviceweek").getValue();

    var ServiceDate ="";

    ServiceDate= Xrm.Page.getAttribute("new_servicedate").getValue().toString();

    Xrm.Page.getAttribute("new_name").setValue(Name + ServiceCalWeek + ServiceDate);

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

  • Suggested answer
    Hamzeh Zawahreh Profile Picture
    3,674 on at

    hello, try this for sample, create auto serial number (by add date to feild name)

    function SetAutoNumber()

    {

    var dateFieldValue = Xrm.Page.getAttribute("date_field_name").getValue();

    // create the yyyy-mm-dd string

    var year = dateFieldValue.getFullYear()+"";

    var month = (dateFieldValue.getMonth()+1)+"";

    var day = dateFieldValue.getDate()+"";

    var dateFormat = year + "-" + month + "-" + day;

    var autonumberFieldValue = Xrm.Page.getAttribute("autonum_field_name").getValue();

    var result = dateFormat + "-" + autonumberFieldValue;

    Xrm.Page.getAttribute("the_other_field_name").setValue(result);

    }

    ************************** OR use workflow Like This link below ******************

    [View:https://crmramblingsbysteven.wordpress.com/2012/05/22/how-to-concatenate-two-fields-using-workflow-in-dynamics-crm-2011/:550:0]

  • Community Member Profile Picture
    on at

    ok so I tried to code Chitra provided and Ranj provided, both worked. however, the format is this -

    Remote ServicesMon May 18 2015 00:00:00 GMT-0500 (Central Standard Time)Mon May 18 2015 00:00:00 GMT-0500 (Central Standard Time)

    I get that this is the SQL value format, but is there any way to just pull  'Mon May 18' or '5/18/15' format by chance?

    I am able to use a workflow to copy over the value from the field which is 5/18/15 but obviously when using JavaScript it's a completely different story.

    Thanks guys you're the best!!

  • Community Member Profile Picture
    on at

    I think I am just going to do a workflow on this one, because I have to also do a check to see if the data exists, not sure how to do that, unless someone can help me with it?

    Upon testing, I noticed that every time I opened the record, it input the data from the three fields I'm trying to concatenate, maybe I should do a clear on the name field prior to inputting the new value? I dunno, what's your guys opinion??

    The goal is to just concatenate the fields on create, then if the value changes, remove the old data from 'name' and concatenate into the name field again.

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at

    ADam,

    Workflow should be okay.

    But, if its field has no data, your field will be also not completed, can be only two of 3 value from the field.

  • Community Member Profile Picture
    on at

    yea this is rough, I can't think through it in my head hmm...

    I'm going to need a new field where I can rip the name from (remote service or onsite service), then concatenate two fields instead of three using some javascript or a workflow.

  • Verified answer
    Community Member Profile Picture
    on at

    So I added another field, put several options like remote service, etc in the option set list and put that on the form, I then hid the name field, built a workflow to take the selection of location schedule (new option set field), service date, and concatenate those two fields in the name field, which will display on the views and charts etc... perfect works great, thanks for the help, I should of thought that through better but I appreciate everyone's assistance.

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