Skip to main content

Notifications

Service | Customer Service, Contact Center, Fie...
Suggested answer

Prevent case creation

Posted on by 111

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
    RudyZhang 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
    Ibakordor Kharmih 111 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
    RudyZhang 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

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