Announcements
No record found.
I want to call the web resource function on click of the sub-grid + button.
Actually, I want to prevent sub-grid to add more than one record. And sub-grid has the note attached.
*This post is locked for comments
Hi Pawan ,
Try to add enable rule with custom JavaScript where you need to check how many record is there in the sub-grid .
Using the Ribbon Workbench, customise the 'Add Existing {0}' / 'Add new {0}' commands and call your custom Javascript function there.
If no records exist, you can call the system function which was benig rpeviously called.
Else, you can present your own error message which says not to add any more records.
@Shidin haridas, i tried to add command to Add existing/ add new button on subgrid, but is was in disable state, i think i wont allow to add any function on button Correct me if i am wrong, Instead you can do following thing,
1) Create a javascript function which will be called on page load, Get the number of record from the subgrid entity add that number on your main entity form in dummy field, and then you can use enable rule to hide/show subgrid add button by using below link,
ribbonworkbench.uservoice.com/.../489288-show-or-hide-the-add-new-button-on-form-sub-grid
Best Regards,
Shahbaaz
Thanks for the reply, I have created the command and add the custom enable rule. And return true/false flag through the custom rule web resource. If I am returning true/false hardcoded then it works fine. but if I am returning the flag based on some validation so it takes some time, therefore, it's not working. Please help to resolve the issue.
What type of validation you are doing ? make sure your function should return true or false in single path and its should be synchronous , no matter how long time its taking .
It will be good if you post your code here -
Thanks Goutam, My codes are returning the result as expected but Sub-Grid button not working based on this value.
function countDocumentSubmissionRecord(){ var id = Xrm.Page.data.entity.getId(); var getIDD = id.substr(1, id.length-2); var Flag=Xrm.Page.getAttribute("jitr_Doc").getValue(); if(Flag==false){ var performSomeAction = function(resstatus) { var val = resstatus; if(val == true){ console.log("Inside true"); return true; }else{ console.log("Inside false"); return false; } } countRecord(performSomeAction); } else{ return true; } } function countRecord(callback){ var resstatus; var id = Xrm.Page.data.entity.getId(); var getIDD = id.substr(1, id.length-2); var req=new XMLHttpRequest(); req.open("GET",Xrm.Page.context.getClientUrl()+"/api/data/v8.2/jitr_submissions?$filter=_jitr_caseid_value eq ("+getIDD+")",true); req.setRequestHeader("OData-MaxVersion","4.0"); req.setRequestHeader("OData-Version","4.0"); req.setRequestHeader("Accept","application/json"); req.setRequestHeader("Content-Type","application/json;charset-utf-8"); req.setRequestHeader("Prefer","odata.include-annotations=\"*\""); req.send(); req.onreadystatechange=function(){ if(this.readyState===4){ req.onreadystatechange=null; if(this.status===200){ var result=JSON.parse(this.response); var count = result.value.length; if(count==0){ resstatus=true; callback.apply(this,[resstatus]); } else if(count==1){ resstatus=false; callback.apply(this,[resstatus]); } else{ resstatus=false; callback.apply(this,[resstatus]); } } } else{ } }; }
If I am returning them to the below code then it works fine.
function countDocumentSubmissionRecord(){ var id = Xrm.Page.data.entity.getId(); var getIDD = id.substr(1, id.length-2); var Flag=Xrm.Page.getAttribute("jitr_Doc").getValue(); if(Flag==false){ return false; //or //return true; } else{ return true; } }
Hi ,
Try with synchronous call by setting false -
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/jitr_submissions?$filter=_jitr_caseid_value eq (" + getIDD + ")", false);
In addition -
Get flag value -
var flag = countRecord(performSomeAction); return flag;
Make it synchronous and return at the end -
function countRecord() { var resstatus; var id = Xrm.Page.data.entity.getId(); var getIDD = id.substr(1, id.length - 2); var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/jitr_submissions?$filter=_jitr_caseid_value eq (" + getIDD + ")", false); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json;charset-utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.send(); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); var count = result.value.length; if (count == 0) { resstatus = true; } else if (count == 1) { resstatus = false; } else { resstatus = false; } } } else { } }; return resstatus; }
Hi Goutam,
I have changed the code as you sent and It does not work for me.
Thanks
Pawan
Is it possible to create Routing Rule for an custom entity in MS CRM 2016
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.
Congratulations to our 2026 Super Stars!
We are thrilled to have these Champions in our Community!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
ScottDurow 2
GJones 1