Skip to main content

Notifications

Announcements

No record found.

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! 

  • RE: Lock Web Resource

    Yes, thank you very much!

  • cloflyMao Profile Picture
    cloflyMao 25,202 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.

  • Verified answer
    cloflyMao Profile Picture
    cloflyMao 25,202 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

  • 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.  

  • cloflyMao Profile Picture
    cloflyMao 25,202 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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

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,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans