Skip to main content

Notifications

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

JavaScript to clear lookup value in portal form

Posted on by 5

Hi everyone,

I'm quite new working with power portals and can not find a solution. I believe there exists very simple code which would help me out.

I need to reset the lookup value (city) of the field when another one is changed (province) when editing or creating a new record. So far I have the below code but it just resets the lookup value, but doesn't  clear it from the form and doesn't let me save the form (city is required field), so it's a bit confusing, maybe I just left a mistake in code:

$(document).ready(function () {
$("#cr52c_province").change(resetfield);
resetfield();
});

function resetfield() {
$("#cr52c_city").attr("value",null);
$("#cr52c_cityId").attr("value",null);
$("#cr52c_city").attr("value",null);
}

Moreover, the form cannot be saved even if the province field is not modified, so every time when the form is opened in edit mode, the city needs to be selected once again in order to save the edited form.

  • Suggested answer
    oliver.rodrigues Profile Picture
    oliver.rodrigues 4,052 on at
    RE: JavaScript to clear lookup value in portal form

    Please use PowerUsers forum for new Portal questions:

    powerusers.microsoft.com/.../PowerAppsPortals

    ------------

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans