cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
neil396
Frequent Visitor

Reset fields that are part of cascading on value change?

Dear all,

 

I'm working on a model driven app where I have 'Province', 'City' and 'Health center' tables. There a relationships active between these tables. (One province has many cities, one city has many health centers.)

 

When creating a form filtering the options down from Province to City to Health center works great with the help of Related Records Filtering but after I have selected a health center I can still change the Province and or City. This results in an invalid combination of health center / province / city.

 

Is there a way to solve this issue? Would it be possible to 'reset' the fields after a value is updated for example? Open for any other solutions.

 

Your help is much appreciated, thanks in advance.

 

Best,

 

Neil

1 ACCEPTED SOLUTION

Accepted Solutions
AhmedSalih
Most Valuable Professional
Most Valuable Professional

@neil396, all logical names must be between single quotes or double quotations:

 

function DisableFields(executionContext) {
    var formContext = executionContext.getFormContext();
    var healthCenter = formContext.getAttribute('adit_healthcenter').getValue();
    var province = formContext.getControl('adit_province');
    var city = formContext.getControl('adit_city');

    if (!healthCenter) //Check if Health Center is Selected
    { province.setDisabled(false); city.setDisabled(false); }
    else { province.setDisabled(true); city.setDisabled(true) ;};
}

 

 

Regards,

Ahmed

If my reply helped you, please give a 👍. And if it has solved your issue, please consider a 👍 & Accepting it as the Solution to help other members of the community find it more.

My Blog: www.powerplatformplace.com

View solution in original post

14 REPLIES 14

Hi @Drrickryp,

 

Thanks for your swift response. I've read the thread, unless I'm mistaking (what defenitely could be the case), I don't think it is applicable to my situation. Maybe it helps if I try to explain my issue in other phrasing. Let's say that I've created a model driven app that contains a table that tracks distribution of products. I have the following relationships:

 

  • One to many from distribution to provinces
  • One to many from distribution to cities
  • One to many from provinces to cities

Now, for the distribution table I have created a form with two lookup fields: Province and City. I'm trying to achieve two things:

 

  1. If I select either Province or City first, the values that I can select for the other field should be filtered.
    1. If I select a province first I should only be able to pick the cities that are related to that province (this works via related records filtering).
    2. If I select a city first I should only be able to pick the province that is related to that city.
  2. Invalid combinations of Province / City should be prevented.
    1. The related records filtering makes sure I can only select cities that are in a specific province. My issue is that after both fields are filled, I can change the province field whilst the city field doesn't change.
    2. The above results in an invalid combination of province and city
    3. I would like to achieve that If once update the province field, the city field value gets deleted and I need to reselect a new city that is linked to the updated province.

I hope this makes it better to understand. If the solution is indeed towards the type of relationships maybe you can point me a bit into the right direction?

 

Thanks again and best,

 

Neil

@neil396 

Could you post a screenshot of your form please?

Hi, @Drrickryp 

 

Of course, happy to! Please find the following screenshots below.

  1. States
  2. Cities (that are related to states)
  3. Related record filtering settings on the distribution form
  4. Related record filtering in action on the distribution form
  5. Saved a distribution record with matching state and city
  6. Updated the state whilst I did not have to update city, result is an invalid combination of state and city
  7. State_City relationship details
  8. Distribution_City relationship details
  9. Distribution_State relationship details

Hope this helps, please let me know if you need more input. Thanks again!

 

Best,

Neil

 

StatesStatesCitiesCitiesRelated record filtering settingsRelated record filtering settingsRelated record in action in formRelated record in action in formInitial saveInitial saveUpdate stateUpdate state

City - state relationshipCity - state relationshipDistribution - city relationshipDistribution - city relationshipDistribution - State relationshipDistribution - State relationship

@neil396 

This could be done easily in a canvas app form simply by blanking the city field when the state field is changed.  I am not as familiar with the mda form.  Perhaps @AhmedSalih , who is more familiar with model driven apps has a simple answer for you. 

@Drrickryp 

 

Thanks for getting back to me and the referral to @AhmedSalih, I hope he maybe has a solution. Yeah I can imagine this is easier done with a canvas app. I did quite some Googling before reaching out to the community, most hits were related to canvas apps.

 

It seems like a rather 'simple' issue so now I'm annoyed with myself that I haven't found the solution yet and I'm determined to figure it out! 😉

 

Anyway thanks again for your input and I hope someone else has an answer.

 

Best,

 

Neil

AhmedSalih
Most Valuable Professional
Most Valuable Professional

Hello, @neil396, you will have to create a web resource using JavaScript to Disable/Hide the Province and or City Fields once the Health Center is Selected. You will need to run the function on the OnChange event of your Health Center Field.

Use this code for your web resource: (Use your Logical Names of the Fields when Mentioned)

 

function DisableFields(executionContext) {
    var formContext = executionContext.getFormContext();
    var healthCenter = formContext.getAttribute(HealthCenterFieldLogicalName).getValue();
    var province = formContext.getControl(ProvinceFieldLogicalName);
    var city = formContext.getControl(CityFieldLogicalName);

    if (!healthCenter) //Check if Health Center is Selected
    { province.setDisabled(false); city.setDisabled(false); }
    else { province.setDisabled(true); city.setDisabled(true) ;};
}

 

 

 

Regards,

Ahmed

If my reply helped you, please give a 👍. And if it has solved your issue, please consider a 👍 & Accepting it as the Solution to help other members of the community find it more.

My Blog: www.powerplatformplace.com

Hi @AhmedSalih,

 

Thank you for reaching out so quickly and your help offered! I'm travelling for the next couple of days and probably won't have time to check out your solution before Friday.

 

It makes sense and I'm sure it will work, I will get back to this thread latest by Friday and of course accept as solution then.

 

Thanks again.

 

Best,

 

Neil

Hi @AhmedSalih ,

 

I've followed your instructions and created the web resource that is triggered by change of the Health Center field. When I pick a value for the Health Center, I get the error message displayed in the screenshots. I've also included the error log.

 

I've double checked the logial names and also tried both 'function DisableFields(executionContext)' and 'DisableFields(executionContext)' as funtion for the event.

 

I have no experience regarding JavaScript so it might be something simple. One last push in the right direction would be much appreciated!

 

Thanks again.

 

Best,

 

Neil

 

neil396_0-1660986225961.png

neil396_1-1660986262330.png

neil396_2-1660986306705.png

 

ReferenceError: Web resource method does not exist: DisableFields(executionContext)
at y._handleMethodNotExistError (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:2022:5003)
at y.execute (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:2022:3677)
at https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:156:26686
at i (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:328:88)
at ee._executeIndividualEvent (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:156:26660)
at ee._executeEventHandler (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:156:23665)
at Object.execute (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:156:23093)
at N._executeSyncAction (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:939:692)
at N._executeSync (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:939:419)
at N.executeAction (https://orgbdfe41b9.crm4.dynamics.com/uclient/scripts/app.js?v=1.4.4573-2207.3:939:201)

Error Details:
Event Name: onchange
Function Name: DisableFields(executionContext)
Web Resource Name: cr37b_disablefieldsv3
Solution Name: Active
Pub

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,413)