Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can I auto populate a field based off of other fields?

(0) ShareShare
ReportReport
Posted on by 2

I have a field called, "Description" and I need this field to auto populate the Year from the field called, "Effective Start Date" and then grab the value from the Contract ID field and the value from the PBP field.

The format that is needed is CYyyyy (the contract id value) (the PBP value)

Any help is appreciated, thank you.

*This post is locked for comments

  • Suggested answer
    Drew Poggemann Profile Picture
    Drew Poggemann 4 on at
    RE: How can I auto populate a field based off of other fields?

    Hi USA80,

    I did the following in a simple workflow after installing Jason Lattimer's Date Time Utils (https://github.com/jlattimer/CRM-DateTime-Workflow-Utilities)

     

    1.  Created real time workflow on My Account Entity that will do the following steps:

    calculated_5F00_description.PNG

    First step was to get the year using Jason's date time utils.  I pulled from CreatedDate in my example

    Second step was to update my Account's Calculated Description field with the concatenation:

    CY-'>{Account Number(Account)}-'>{Year Number(Get Year Number using Date / Time Utils)}

    That is all I need to do.

    Note, the function Jason provides has a "comma" in the year.  not sure if this is driven off your setup for number formats in CRM or if you need to work with him to strip that off.

    calculated_5F00_description.PNG

    Hope this helps.

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    I found where to remove the ()

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    OK, I found the issue...but instead of () around the Carrier Id and PBP, can I just do spaces?

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    Here is the script:

    function CalculateDescription() {

      var EffectiveStartDate = "nhs_effectivestartdate";

      var ContractId = "nhs_contractid";

      var PBPValue = "nhs_pbp";

      var Description = "nhs_description";

      var CalulatedDescription = "CY"; //CYyyyy (the contract id value) (the PBP value)

      var VALUE_EffectStartDate = Xrm.Page.getAttribute(EffectiveStartDate).getValue();

      var VALUE_ContractId = Xrm.Page.getAttribute(ContractId).getValue();

      var VALUE_PBPValue = Xrm.Page.getAttribute(PBPValue).getValue();

      // Append Year

      if (VALUE_EffectStartDate != null && VALUE_EffectStartDate != "") {

          Value_CalulatedDescription = Value_CalulatedDescription + VALUE_EffectStartDate.getFullYear();

      }

      // Append Contract ID

      Value_CalulatedDescription = Value_CalulatedDescription + "(";

      if (VALUE_ContractId != null && VALUE_ContractId != "") {

          Value_CalulatedDescription = Value_CalulatedDescription + VALUE_ContractId;

      }

      Value_CalulatedDescription = Value_CalulatedDescription + ")";

      // Append  PBPValue

      Value_CalulatedDescription = Value_CalulatedDescription + "(";

      if (VALUE_PBPValue != null && VALUE_PBPValue != "") {

          Value_CalulatedDescription = Value_CalulatedDescription + VALUE_PBPValue;

      }

      Value_CalulatedDescription = Value_CalulatedDescription + ")";

      // Set Value

      Xrm.Page.getAttribute(SCHEMA_CalculatedDescription).setValue(Value_CalulatedDescription)

    }

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    pic1-_2800_2_2900_.pngpic-_2800_2_2900_.png

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How can I auto populate a field based off of other fields?

    I have tried that script and it did worked for me.. can you share a screenshot/log file (if any)?

    Also try refresh page or new browser/ingognito mode.

    Also can you share your updated code her just to check the syntax etc.

    hope this helps.

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    I think the reason is I need to pull out the Month, Day and year from the date string that it captures.  Just not sure how to do that.

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    I tried your script with putting in the correct schema names and I get an error that says, 'Value_CalculatedDescription' is undefined

  • Suggested answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: How can I auto populate a field based off of other fields?

    Hi USA,

    Sorry I may have jumped into Plugin too quickly. You can actually use JavaScript to achieve this requirement. I have tried and it works perfectly.

    1) The below script assumed that your field "Effective Start date" is a datetime field and all other fields are text field. If this is not true then the below script may not work and will require some further changes.

    2) You need to replace the schema name of your fields.

    3) You need to register this method on change of Effective Start Date, Contract ID & PBP Value field.

    3) It would be good idea to make Effective Start Date, Contract ID & PBP Value field as mandatory cause if not then you may see unexpected value in the Description field. And also make the Description field as read only.

    PBPValue.png

    =========================================
    
    function CalculateDescription() {
    
       var SCHEMA_EffectiveStartDate = "new_effectivestartdate";
    
       var SCHEMA_ContractId = "new_contractid";
    
       var SCHEMA_PBPValue = "new_pbpvalue";
    
       var SCHEMA_CalculatedDescription = "new_calculateddeciption";
    
       var Value_CalulatedDescription = "CY"; //CYyyyy (the contract id value) (the PBP value)
    
       var VALUE_EffectStartDate = Xrm.Page.getAttribute(SCHEMA_EffectiveStartDate).getValue();
    
       var VALUE_ContractId = Xrm.Page.getAttribute(SCHEMA_ContractId).getValue();
    
       var VALUE_PBPValue = Xrm.Page.getAttribute(SCHEMA_PBPValue).getValue();
    
       // Append Year
    
       if (VALUE_EffectStartDate != null && VALUE_EffectStartDate != "") {
    
           Value_CalulatedDescription = Value_CalulatedDescription + VALUE_EffectStartDate.getFullYear();
    
       }
    
       // Append Contract ID
    
       Value_CalulatedDescription = Value_CalulatedDescription + "(";
    
       if (VALUE_ContractId != null && VALUE_ContractId != "") {
    
           Value_CalulatedDescription = Value_CalulatedDescription + VALUE_ContractId;
    
       }
    
       Value_CalulatedDescription = Value_CalulatedDescription + ")";
    
       // Append  PBPValue
    
       Value_CalulatedDescription = Value_CalulatedDescription + "(";
    
       if (VALUE_PBPValue != null && VALUE_PBPValue != "") {
    
           Value_CalulatedDescription = Value_CalulatedDescription + VALUE_PBPValue;
    
       }
    
       Value_CalulatedDescription = Value_CalulatedDescription + ")";
    
       // Set Value
    
       Xrm.Page.getAttribute(SCHEMA_CalculatedDescription).setValue(Value_CalulatedDescription)
    
    }
    
    =========================================

    On a side note, If you haven't used plugin yet then it would be good to get the understanding of it as it will help you achieve not only this but other requirements which cannot be achieved using BR, workflow etc.

    You can go through the below document about creating & registering plugin.

    https://msdn.microsoft.com/en-us/library/gg328263.aspx

    https://msdn.microsoft.com/en-us/library/gg594416.aspx

    msdn.microsoft.com/.../gg309620.aspx

    Hope this helps.

  • USA80 Profile Picture
    USA80 2 on at
    RE: How can I auto populate a field based off of other fields?

    I have never done that, can you help me get this to work?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans