Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Fields Hidden via JS Displayed After Refresh

Posted on by 279

I have a form where all sections are hidden by default. Depending on the value of a field, one of the sections is shown. When an action is taken in that section by clicking an HTML button in a web resource, some fields and the button in the section are hidden while other fields are shown, the form is set to inactive, saved and refreshed. At this point everything displays correctly.

However, when I refresh the form again, all of the visibility changes I made are reversed. I can't find anything in my code that could be doing this onLoad unless the setVisible function for a section also restores all the components within that section to their default visibility. I've also removed the part of my code in the onLoad section below and set all my sections as shown by default. This issue still persists.

Here are the relevant portions of my code:

onLoad:

... 
var tabObj = window.parentFormContext.ui.tabs.get("General");

var sectionRFI = tabObj.sections.get("RFI INFO");
var sectionGI = tabObj.sections.get("GENERAL INQUIRY INFO");
var sectionCV = tabObj.sections.get("PERSONAL CAMPUS VISIT INFO");
var sectionSMS = tabObj.sections.get("SMS RESPONSE");

var engagementType = window.parentFormContext.getAttribute("new_engagementtype").getValue();

switch (engagementType) {
case 100000000:
sectionRFI.setVisible(true);
if (window.parentFormContext.getAttribute('new_rfiinternationalrequest').getValue()) {
window.parentFormContext.getControl('new_rfiinternationalrequest').setVisible(true);
window.parentFormContext.getControl('new_rfiinternationalrequestemailrecord').setVisible(true);
window.parentFormContext.ui.quickForms.get('ContactsMailingAddress').setVisible(false);
window.parentFormContext.getControl('WebResource_ebiprintlabelbutton').setVisible(false);
}
break;

case 100000001:
sectionGI.setVisible(true);
break;

case 100000002:
sectionCV.setVisible(true);
break;

case 100000003:
sectionSMS.setVisible(true);
break;

default:
break;
};


onClick:
const today = new Date();

window.parentFormContext.getAttribute('new_rfilabelprinteddate').setValue(today);
window.parentFormContext.getControl('new_rfilabelprinteddate').setVisible(true);

window.parentFormContext.getControl('WebResource_ebiprintlabelbutton').setVisible(false);

deactivateForm();


deactivateForm:

window.parentFormContext.getAttribute('statecode').setValue(1);
window.parentFormContext.data.refresh(true);
  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Fields Hidden via JS Displayed After Refresh

    Hey Sam! Thanks for your help. That worked perfectly!

    Do you know why it reverts to the controls default visibility on refresh? Does the client API not permanently change that setting? If so, why can it permanently change other things, like enable/disable of controls?

  • Verified answer
    Inogic Profile Picture
    Inogic 24,094 on at
    RE: Fields Hidden via JS Displayed After Refresh

    Hi Lucas,

    I checked your comments with code where you have HTML web resource on form. And on click of HTML button from that web resource, you are Deactivating current record and adding visibility to “new_rfilabelprinteddate” and “WebResource_ebiprintlabelbutton” controls.

    And once you refresh the form, it restores those controls to their default visibility.

    But I didn’t find condition in your code to show/hide controls if the record is deactivated (i.e., statecode == 1). This might cause an issue for you.

    Can you please add the condition of “statecode == 1” in onLoad function and again set the visibility to controls whatever you set in the onClick function?

    Hope this helps.

    Thanks!

  • Lucas H Profile Picture
    Lucas H 279 on at
    RE: Fields Hidden via JS Displayed After Refresh

    Thanks for the reply, Ossama!

    Unfortunately, that didn't work. I even added only formContext.data.entity.save() in "deactivateForm" and the issue is still present.

    My understanding was that formContext.data.entity.refresh(true) would first save and then refresh the form so I didn't think I needed to use the separate save method.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Fields Hidden via JS Displayed After Refresh

    Hi,

    as per my understanding, you need to add a line of save in the last script "deactivateForm"

    formContext.data.entity.save()

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans