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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Call Webresource function on click of sub-grid + button

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • gdas Profile Picture
    50,091 Moderator on at

    Hi Pawan ,

    Try to add enable rule with custom JavaScript where you need to check how many record is there  in the sub-grid .

  • Suggested answer
    Shidin Haridas Profile Picture
    3,499 on at

    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.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    @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

  • Community Member Profile Picture
    on at

    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.

  • gdas Profile Picture
    50,091 Moderator on at

    Hi Pawan ,

    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 -

  • Community Member Profile Picture
    on at

    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;
    	}	  
    }
    


  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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);
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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;
    }


  • Community Member Profile Picture
    on at

    Hi Goutam,

    I have changed the code as you sent and It does not work for me.

    Thanks

    Pawan

  • Ayushi Goyal Profile Picture
    5 on at

    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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans