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 :
Customer experience | Sales, Customer Insights,...
Answered

Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

(0) ShareShare
ReportReport
Posted on by

Hello, in my "Opportunity" form, I have a "Sales Quota Distribution" entity grid.  This grid contains a "Resource" field, which is a lookup to the User entity.  I want to stop users from saving when the same "Resource" has been entered in the Sales Quota Distribution grid more than once.  How can I do this?

Thanks!

I have the same question (0)
  • Verified answer
    rthompson Profile Picture
    1,532 on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    You can using a plugin on pre-validate or pre-operation.

    Or

    You can using javascript by creating a original variable.

    Create a global variable var origDataSheetStage = null;

    Then create a load function and OnChange that would do something like this

    function LoadForm(executionContext) {
    
    var formContext = executionContext.getFormContext(); // get formContext
    
    var dataSheetStage = formContext.getAttribute('new_datasheetstage').getValue();
      if (dataSheetStage !== null) {
         origDataSheetStage = dataSheetStage;
      }
    }
    
    function OnChange(executionContext) {
    
      var formContext = executionContext.getFormContext(); // get formContext
    
      var dataSheetStage = formContext.getAttribute('new_datasheetstage').getValue();
    
      if (dataSheetStage != origDataSheetStage && dataSheetStage > 0) {
         formContext.getAttribute.setValue(origDataSheetStage);
      }
    }
    

  • Community Member Profile Picture
    on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    @rthompson, Thanks!

    I am not experienced with plugins, do I just download the latest version of Visual Studio, open up a "Class Library (.NET Framework)" project, paste this code in there with the correct field names?

    Also, would it be possible to use this code as an OnLoad event web resource instead?

  • Suggested answer
    Marco.P Profile Picture
    2,405 on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Hi tgiard,

    the code posted by rthompson is javascript and you cannot paste it and use it for your plugin.

    Also plugin run server side, so you can trigger then on "message" like pre-validate or pre-operation.

    Instead you can call javascript function on OnLoad and OnSave event.

    Here's some useful links :

    carldesouza.com/.../

    theonedynamics.com/.../

    Hope it helps!


    If you found the answer helpful for you or other readers, please mark as Verified .

  • Community Member Profile Picture
    on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Thank you @Marco.P.  I created an "OnLoad" event using the LoadForm function but received the following error:
    ScriptErrorWebResource.PNG

    Any ideas how I can get rid of this error?  Could it be because my Resource field has a lookup field type?

    Below is my code for the OnLoad event.  All I changed is the field name:

    function LoadForm(executionContext) {
    var formContext = executionContext.getFormContext(); // get formContext
    var dataSheetStage = formContext.getAttribute('new_resource').getValue();
      if (dataSheetStage !== null) {
         origDataSheetStage = dataSheetStage;
      }
    }
    Thanks!

  • Suggested answer
    rthompson Profile Picture
    1,532 on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Hi tgiard,

    What type of field is the "new_resource"?

    Also in the form or field did you check this box?

    formInfo.JPG

  • Community Member Profile Picture
    on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Yes, I did check the box.  “New_resource” is a lookup field to the User entity.

  • Suggested answer
    rthompson Profile Picture
    1,532 on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Are you using in the javascript code "New_resource" or "new_resource"?

    Should be "new_resource".

    This should work.  It is standard code.

  • Community Member Profile Picture
    on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    I am using "new_resource".  I'm wondering if the issue is occurring because I am loading the "Opportunity" entity form, which contains a "Sales Quota Distribution" entity grid.  The "new_resource" field is in the "Sales Quota Distribution" entity.  Could that be the issue?

  • rthompson Profile Picture
    1,532 on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    If you could send a some screenshots that would be very helpful to help you with your issue.

  • Community Member Profile Picture
    on at
    RE: Need help stopping a user from saving when the same "Resource" has been entered in a grid more than once

    Yes, please see screenshot below:

    4846.Grid.PNG

    You'll notice I am opening an "Opportunity" form, which has a "Sales Quota Distribution" entity grid in it.  One Opportunity record can be associated to many Sales Quota Distribution records. I'd like to be able to check if there are more than 1 of the same "Resource" in the Opportunity form's Sales Quota Distribution grid, and prevent the user from saving/show an error message if there are.

    Hope that helps!

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 179

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 127 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans