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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Model Driven app looku...
Power Apps
Suggested Answer

Model Driven app lookup field validation using javascript web resource

(1) ShareShare
ReportReport
Posted on by 2
i have a work flow group form and when you click on each workflow group you can add resources to them. 
1 resource can be only added to 1 work flow group.
i have a client form where i have a resource allocation tab and in that i can add new resources to a client.
so, for example, if jay is assigned to workflow group 2 (WG2) than that resource cannot be added to workflow group 3 (WG3)
 
 

So in the Screenshot below i have added jay to be part of (WG3) but jay was initially added to (WG 2)
when user tries to save this they should get an error saying jay belongs to a wg2


I was told to use a javascript web resource to achieve this. This is the javascript i have got so far and it is triggering on save even of the form.
 
function validateResourceWorkflowGroup(executionContext) {
    var formContext = executionContext.getFormContext();
  
    // Get the selected Resource and Workflow Group values
    var resourceId = formContext.getAttribute("icando_resource").getValue();
    var workflowGroupId = formContext
      .getAttribute("icando_workflowgroup")
      .getValue();
      var fetchXml = `?fetchXml=
      <fetch mapping='logical'>
         <entity name='icando_clientresourceallocation'>
            <attribute name='icando_resource'/>
            <attribute name='icando_workflowgroup'/>
               <filter type='and'>
                  <condition attribute='icando_resource' operator='eq' value='`+resourceId[0].id+`'/>
               </filter>
         </entity>
      </fetch>`;
  
  Xrm.WebApi.retrieveMultipleRecords("icando_clientresourceallocation", fetchXml).then(
      function success(result) {
          for (var i = 0; i < result.entities.length; i++) {
              console.log(result.entities[i]);
          }                    
  
          // perform additional operations on retrieved records
      },
      function (error) {
          console.log(error.message);
          // handle error conditions
      }
  );

i am getting a scripting error for any resource i save. How can i do proper validation so that when a resource is added to a wrong workflow group users gets an error.

Categories:
I have the same question (0)
  • Suggested answer
    MichaelFP Profile Picture
    1,991 Moderator on at
    I would recommend to no use that on save. In save you need to cancel the process before do it your validation.
     
    You must use the onChange() of the lookup field, and once the validation occurs you can set a error so the system will not allow the user to save the record because has error in the form validation. You can achieve that using AddNotification,
     
     
    you can add the notification of type error on the field and it can show a custom message and will block to save the record. it will be more cleaner e easy to manage that.
     
    If my answer helped you, please give me a thumbs up (👍). If solve your question please mark as answer ✔️. This is help the community.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,055

#2
Valantis Profile Picture

Valantis 666

#2
11manish Profile Picture

11manish 666

Last 30 days Overall leaderboard