Skip to main content

Notifications

Announcements

No record found.

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

  • Ayushi Goyal Profile Picture
    Ayushi Goyal 5 on at
    RE: Call Webresource function on click of sub-grid + button

    Is it possible to create Routing Rule for an custom entity in MS CRM 2016

  • RE: Call Webresource function on click of sub-grid + button

    Hi Goutam,

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

    Thanks

    Pawan

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Call Webresource function on click of sub-grid + button

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


  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Call Webresource function on click of sub-grid + button

    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);
  • RE: Call Webresource function on click of sub-grid + button

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


  • gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Call Webresource function on click of sub-grid + button

    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 -

  • RE: Call Webresource function on click of sub-grid + button

    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.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,205 on at
    RE: Call Webresource function on click of sub-grid + button

    @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

  • Suggested answer
    Shidin Haridas Profile Picture
    Shidin Haridas 3,497 on at
    RE: Call Webresource function on click of sub-grid + button

    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.

  • gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: Call Webresource function on click of sub-grid + button

    Hi Pawan ,

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

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans