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

JS script in Classic Mode and UCI issue

(0) ShareShare
ReportReport
Posted on by 159

Hello,

The JS code below works in CRM Classic  mode but doesn't in UCI.   The page  just reloads itself endlessly.

Any clues?

Thank.

function onLoad(executionContext) {

ShowHideBPF(executionContext);

}

function ShowHideBPF(executionContext) {
formContext = executionContext.getFormContext();
debugger;
if (formContext.getAttribute("s_subtype").getValue() === 1) {
formContext.data.entity.save();
formContext.data.process.setActiveProcess("XXXXX-XXXXX-XXXXXXX-XXXXXX", SetProcessVisibility);
}
else if (formContext.getAttribute("s_subtype").getValue() === 2) {
formContext.data.entity.save();
formContext.data.process.setActiveProcess("XXXXX-XXXXX-XXXXXXX-XXXXXX", SetProcessVisibility);
}
else if (formContext.getAttribute("s_subtype").getValue() === 3 {
formContext.data.entity.save();
formContext.data.process.setActiveProcess("XXXXX-XXXXX-XXXXXXX-XXXXXX", SetProcessVisibility);
}
else if (formContext.getAttribute("s_subtype").getValue() === 4) {
formContext.data.entity.save();
formContext.data.process.setActiveProcess("XXXXX-XXXXX-XXXXXXX-XXXXXX", SetProcessVisibility);
}
else {
formContext.ui.process.setVisible(false);
}
}

  • Suggested answer
    Kahspot Profile Picture
    Kahspot 159 on at
    RE: JS script in Classic Mode and UCI issue

    Hello rexkenley,

    Thanks for your help.

  • Verified answer
    rexkenley Profile Picture
    rexkenley 110 on at
    RE: JS script in Classic Mode and UCI issue

    You are missing a closing parenthesis in your code.

    else if (formContext.getAttribute("s_subtype").getValue() === 3 {

    Should be

    else if (formContext.getAttribute("s_subtype").getValue() === 3) {

    I refactored your code, let me know if you have questions

    function ShowHideBPF(executionContext) {
      const formContext = executionContext.getFormContext(),
        s_subtype = formContext.getAttribute("s_subtype").getValue(); // calling this once is better calling it repeatedly
    
      let guid;
    
      switch (s_subtype) {
        case 1:
          guid = "XXXXX-XXXXX-XXXXXXX-XXXXXX";
          break;
        case 2:
          guid = "XXXXX-XXXXX-XXXXXXX-XXXXXX";
          break;
        case 3:
          guid = "XXXXX-XXXXX-XXXXXXX-XXXXXX";
          break;
        case 4:
          guid = "XXXXX-XXXXX-XXXXXXX-XXXXXX";
          break;
        default:
          formContext.ui.process.setVisible(false);
          return;
      }
    
      formContext.data.entity.save();
      formContext.data.process.setActiveProcess(guid, SetProcessVisibility);
    }
    

  • thonda Profile Picture
    thonda on at
    RE: JS script in Classic Mode and UCI issue

    Hi Kahspot,

    Is it still continuously reloading form?

    Can you please provide your script modified to suit any OOB entity form and BPF and while the issue being reproduced?

    Regards,

    Praveen T

    D365 Customizations Support

    Microsoft Corporation

  • Kahspot Profile Picture
    Kahspot 159 on at
    RE: JS script in Classic Mode and UCI issue

    Hello Praveen Thonda,

    Thanks for your reply but  unfortunately your suggestion did not fix the issue. A

  • Suggested answer
    thonda Profile Picture
    thonda on at
    RE: JS script in Classic Mode and UCI issue

    Hi Kahspot,

    Try asynchronous formContext.data.save(saveOptions).then(successCallback, errorCallback); instead of synchronous https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/formcontext-data-entity/save .  I expect this would avoid the form reload, having said that I don't really see the to save on your load as nothing appear to be changed that needs an immediate save.

    Regards,

    Praveen T

    D365 Customization Support

    Microsoft Corporation

  • Kahspot Profile Picture
    Kahspot 159 on at
    RE: JS script in Classic Mode and UCI issue

    Hello,

    Here we are.

    function SetProcessVisibility() {

       formContext.ui.process.setVisible(true);

    }

  • a33ik Profile Picture
    a33ik 84,325 Most Valuable Professional on at
    RE: JS script in Classic Mode and UCI issue

    Hello,

    What is SetProcessVisibility?

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans