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 :
Customer experience | Sales, Customer Insights,...
Answered

Fields Hidden via JS Displayed After Refresh

(0) ShareShare
ReportReport
Posted on by 283

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);
I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

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

    formContext.data.entity.save()

  • Lucas H Profile Picture
    283 on at

    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.

  • Verified answer
    Inogic Profile Picture
    682 on at

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

    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?

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 > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans