web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Service | Customer Service, Contact Center, Fie...
Answered

Lock Web Resource

(0) ShareShare
ReportReport
Posted on by 50

I have added a "lock" field to the same form that this web resource is on.  I would like to prevent the resource from running based on this lock field and display a hidden field in its place.  

Is there a simple way to accomplish this?

I tried adding this at the start and end, but was not successful.

var lockform = Xrm.Page.getAttribute("new_lockworkorder").getvalue();

     if (lockform !== "Yes"){

<The rest of the Script>

}

     else {   

           Xrm.Page.ui.tabs.get("tab_9").sections.get("tab_10_section_1").setVisible(true); 

}

}

Appreciate the assistance! 

I have the same question (0)
  • cloflyMao Profile Picture
    25,210 on at
    RE: Lock Web Resource

    Hi Paul,

    As per my understanding towards your code, it seems that your "lock" field is a single line text field, and you will display and hide web resource and other field based on value of the field.

    To the best of my knowledge, I believe your solution would the most simplest way to accomplish your requirement,

    because web resource could be only hidden by JS code.

    Thus suggestions I could give are:

    1.  Run business rule to control field visibility, only run JS code to control web resource visibility.(Remove some part of original code.)

    2. Migrate deprecated Xrm.Page to replacement formContext.

    Regards,

    Clofly

  • Paul D Richards  Profile Picture
    50 on at
    RE: Lock Web Resource

    Yes, I can use Business Rule for the other field.

    When you said "remove some part of original code" - can you please explain?  The code needs to work when lockworkorder is set to "No".  This is a simple 2 Option field with default of No.

    I changed to:

    var lockform = formContext.getAttribute("new_lockworkorder").getvalue();

        if (lockform !== "Yes"){

    But am not successful.  

  • Verified answer
    cloflyMao Profile Picture
    25,210 on at
    RE: Lock Web Resource

    Hi Paul,

    As per my understanding, it seems that "new_lockworkorder" is an optionset field.

    The value of option in optionset field is integer number, thus formContext.getAttribute("new_lockworkorder").getvalue() will only get number value.

    We can use getText function: formContext.getAttribute("new_lockworkorder").getText(); to get text value of selected option.

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/attributes/gettext

    Regards,

    Clofly

  • cloflyMao Profile Picture
    25,210 on at
    RE: Lock Web Resource

    Hi Paul,

    Could it work for you?

    Regards,

    Clofly

    If you had found any answer helped, please kindly mark as verified to close the thread, it would be really appreciated.

  • Paul D Richards  Profile Picture
    50 on at
    RE: Lock Web Resource

    Yes, thank you very much!

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 36 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans