Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Rollup field to update an optionset field

(0) ShareShare
ReportReport
Posted on by 428

Hi, 

I am running into a requirement to update an optionset field based on the value in rollup field which can go up and down, eg if Rollup = 1, Optionset = Low, if Rollup = 2, Optionset = Medium and so on..

Please suggest if my script is incorrect, will it update the opionset without opening the record and if none of the two options given belowwill work what else i can try?

The two solutions i tried but none seems to be working:

Option 1: 

Use Business Rule to update a temporary field from rollup and then use that temporary field in a workflow to manage the option set values. 

Problem with this approach is that temporary field doesn't get updated until we open the form as business rules seems to work on load or on save which means all our views to show the optionset value will always be incorrect until we open the record. 

Option 2: 

I tried to add javascript on field change (rollup field) below is my code running without error conditions working fine but for some reason it is not setting value and also i am not sure if this will update the optionset without opening the form:

function SetRisk() {


var a = Xrm.Page.getAttribute("jmfloc_vulnerabilityscore").getValue();
if(a == 1 || a== 2 || a==3) 
{

Xrm.Page.getAttribute("jmfinn_amlhighrisk").setValue("Low") ;
}
if(a == 4 || a== 5 || a==6) 
{

Xrm.Page.getAttribute("jmfinn_amlhighrisk").setValue(906010002) ; tried with single, double quotes also
}
if(a == 7 || a== 8 || a==9) 
{

Xrm.Page.getAttribute("jmfinn_amlhighrisk").setValue(906010001) ;
}
if(a >=10) 
{

Xrm.Page.getAttribute("jmfinn_amlhighrisk").setValue(906010000) ;
}

}

 

Thanks,

PS

  • PS10 Profile Picture
    PS10 428 on at
    RE: Rollup field to update an optionset field

    Hi Hao,

    Thanks for your swift reply.

    I have used a workflow in past to mimic the rollup field to show total number of related records created,however this time i struggle with the requirement which is as below:

    We have a subgrid to show related records and on each record there is a score field.

    What my rollup does is, it picks score from each active record and sum up the values to show the total score, if record is deactivated it then decreases the value, also the score can be adjusted at any active record, which then reflects in my rollup.

    And i am struggling to create a logic for the above as how workflow will know score for each modified score and how will it add for each new score on new record.

    For rest of your solutions since i am not a developer i do not know how to write a plugin and we are on-premise and do not use power automate.

    Thanks,

    PS

  • Suggested answer
    LuHao Profile Picture
    LuHao 40,872 on at
    RE: Rollup field to update an optionset field

    Hi PS,

    Whether using business rules or Javascript, their data will only be updated after the form is opened.

    If you do not open the form, such as when viewing data in the view, business rules or Javascript will not work.

    In addition, the rollup field cannot be used as a trigger for workflow or Power Automate.

    So in my opinion there are currently two solutions.

    Solution 1. 

    Use a simple field instead of the rollup field, and then implement the rollup function for it through plug-in or workflow or Power Automate.

    Then create a workflow, the trigger is that when the simple field changed, the step is to update the option set field based on the value of the rollup field.

    Solution 2.

    Use the scheduled cloud flow of Power Automate to update all records of this entity every hour, and update the option set field based on the value of the rollup field.

    In this case, the running time of the flow and the update time of the rollup field are approximately synchronized.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans