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();
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.
Model Driven app lookup field validation using javascript web resource
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.
Was this reply helpful?YesNo
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.