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)

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

(0) ShareShare
ReportReport
Posted on by 26

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

I have the same question (0)
  • Suggested answer
    Hussein Wahba Profile Picture
    223 on at

    There is a lot of ways to map field value

    1- Calculated field, but in this case it will be in the creation of the record.

    2- Business rule, you need to set the value of the field as calculated.

    3- Workflow on create the field: but in this case you will not have a way to set the year in format yyyy.

    4- Plugin pre-operation of create and update of this fields.

    5- Workflow on change of this fields with a code activity to map the values

    Also for a generic solution you can do the following:-

    - create entity has a format combined with field schema names and datetime formats.

    - create plugin to run pre-operation to manage that formatting.

  • Suggested answer
    Drew Poggemann Profile Picture
    4 on at

    Hi USA80,

    First thing I would try is using a calculated field to accomplish your needs.  If that does not work then I usually utilize a workflow with multiple steps and leverage the ability to "Append" information to the field.  Example, first step I would set the description to the Contract Id and the next step I would Append the PBP field.

    Screen-Shot-2018_2D00_07_2D00_17-at-6.45.16-PM.png

    Hopefully this helps.

  • USA80 Profile Picture
    26 on at

    I need it to start with CY(and then the YYYY from the effective start date field), how can I do this?

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi USA,

    I would suggest to write custom code (Plugin/ Workflow to achieve your requirement). This would be easy/ straigt forward and you can include complex logic such as fetching year part from the effective from date.

    Hope this helps.

  • USA80 Profile Picture
    26 on at

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

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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
    26 on at

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

  • USA80 Profile Picture
    26 on at

    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.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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
    26 on at

    pic1-_2800_2_2900_.pngpic-_2800_2_2900_.png

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