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...
Suggested answer

Prevent case creation

(0) ShareShare
ReportReport
Posted on by

Hi, I need to prevent a user from manual case creation for a certain type of account.
The condition is: If Account field equals Internal, pop an error message preventing user from creating the case.

Can you help share solution or the process on how can I do this?

  • Suggested answer
    RudyZhang Profile Picture
    Microsoft Employee on at
    Prevent case creation
    Hi,
     
    Here are some steps to use this sample code.
    1. Edit the application to find the form you need to change


    2. Click Add /On Save/ event to upload this function to /Web Resources/.


    3. Fill in the function to be called and check the box /pass execution context as first parameter/.
    4. Click /Save and Publish/ to publish the form and application.


     
     
     
     
     
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Rudy Zhang
  • Ibakordor Kharmih Profile Picture
    on at
    Prevent case creation
    Thank you for the code, can you share where exactly do I upload the code. Is it on the button or form? Can you share the detailed steps from the start?
  • Suggested answer
    RudyZhang Profile Picture
    Microsoft Employee on at
    Prevent case creation
    Hi,
     
    We have analyzed your requirements, and we think that you can execute a custom JavaScript function on the /On Save/ event of the form that will popup if the value of a field in the form is a specific value and block the save.

    Here is some sample code.
     
    function testfunc(executionContext) {
        // get form context
        var formContext = executionContext.getFormContext(); 
        // replace 'title' with the logical name of your field
        var testfield = formContext.getAttribute("title"); 
    
        if (testfield != null) {
            var testFieldValue = testfield.getValue();
    
            if (testFieldValue == 'TTT') {
                executionContext.getEventArgs().preventDefault(); 
                // show error message
                alert('Error: Cannot create case for Internal account.'); 
            }
        }
    }
    


     
     
     
    I hope my answer is helpful to you! If you have any other questions, please feel free to contact me.
     
    Best Regards,
    Rudy Zhang

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

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans