Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

refreshing UI of dynamc form getting in loop or error

Posted on by 390

Hi All, 

I am trying to lock fields when the NEXT button in a BPF is clicked, I have used the code below, but i found out it only works when you refresh the form. I tried using the code in an onsave event, but i get the pop up that the form isnt saved and even when i click okay, it clears out the form and when i put the code inside the addOnStageChange event of the BPF, he form gets into a loop. Someone help me out, as this looks petty but yet wouldnt work-

function Lockfields(executionContext) {
var formContext = executionContext.getFormContext();

var appRequest = formContext.getAttribute("approval");
if (appRequest != null) {
if (appRequest.getText() == "draw") {
//lock fields
  formContext.getControl("field").setDisabled(true);
  formContext.getControl("field").setDisabled(true);
  formContext.getControl("field").setDisabled(true);

Xrm.Page.data.save().then(Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId()));

    }
   }
}

In Between: How do i paste codes on here, since the change of the UI, i cant paste in a code editor?

*This post is locked for comments

  • Suggested answer
    NODAL Profile Picture
    NODAL 860 on at
    RE: refreshing UI of dynamc form getting in loop or error

    Hi,

    I'm assuming you have approval field on certain bpf stage and you want to lock other fields. Based on value in approval field.

    Create one onload function.and add stage change event.

    Then add your function in "formContext.data.process.addOnStageChange(LockFields)".

    And remove "Xrm.Page.data.save().then(Xrm.Utility.openEntityForm(Xrm.Page.data.entity.getEntityName(), Xrm.Page.data.entity.getId()));".

    Replace "appRequest.getText() == "draw"" with "appRequest.getText() === "draw"".

    You might also want to do same on stage selection i.e.

    formContext.data.process.addOnStageSelected(LockFields);

    Regards,

    Ketan

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

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