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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to call another function variable data to another function mscrm javascript

(0) ShareShare
ReportReport
Posted on by 242

Hi,

I am trying to get another function data to another function for webapi in mscrm but i am not able to get ldata look my example i am calling function like this sectionduplicate=getsectiondetailbyid(aah_sectionid); but that function not able to throw that variable data code as below

var sectionduplicate;
function getassementdata()
{
	
	 var lookupvalue1= parent.Xrm.Page.getAttribute("aah_assessmentid");
    if (lookupvalue1 != null) {
        var lookup = lookupvalue1.getValue();
        if ((lookup != null)) {
            if (lookup[0].id != null) {
                var lookup1 = new Array();//create a new Array
                lookup1[0] = new Object();
                lookup1[0].id = lookup[0].id;//retrieve the id of the record
                lookup1[0].name = lookup[0].name;//retrieve the name of the record
                lookup1[0].entityType = lookup[0].entityType;//retrieve the entitytype
          //here set lookup field one value into second look up Field
		  parent.Xrm.WebApi.online.retrieveMultipleRecords("aah_aah_assessment_aah_section", "?$select=aah_assessmentid,aah_sectionid&$filter=aah_assessmentid eq"+" "+lookup[0].id).then(
			function success(results) {
				for (var i = 0; i < results.entities.length; i++) {
					var aah_assessmentid = results.entities[i]["aah_assessmentid"];
					var aah_sectionid = results.entities[i]["aah_sectionid"];
					
				   sectionduplicate=getsectiondetailbyid(aah_sectionid);
					
					
					
				}
				
			},
			function(error) {
				parent.Xrm.Utility.alertDialog(error.message);
			}
		);
               // Xrm.Page.getAttribute("new_lookupfield2").setValue(lookup1);
            }
           
        }
    }
}

function getsectiondetailbyid(sectionid1)
{
	var sectiondata1="";
	
	parent.Xrm.WebApi.online.retrieveMultipleRecords("aah_section", "?$select=aah_name,aah_sectionid&$filter=aah_sectionid eq"+" "+sectionid1).then(
    function success(results) {
        for (var i = 0; i < results.entities.length; i++) {
            var aah_name = results.entities[i]["aah_name"];
            var aah_sectionid = results.entities[i]["aah_sectionid"];
		    
			

		
			
			 sectiondata1 +=  '   <div class="card" id="' +aah_sectionid +'">  '  + 
		 '       <div class="card-header" role="tab" id="'+aah_name+'">  '  + 
		 '         <h5 class="mb-0">  '  + 
		 '           <a data-toggle="collapse" href="#'+aah_sectionid+'" aria-expanded="true" aria-controls="'+aah_sectionid+'">  '  + 
		 aah_name + 
		 '           </a>  '  +  
		 '         </h5>  '  + 
		 '   </div>  '  + 
		 '   <div id="'+aah_sectionid+'" class="collapse show" role="tabpanel" aria-labelledby="'+aah_sectionid+'" data-parent="#accordion">  '  + 
		 '         <div class="card-body">  '  + 

		 '         </div>  '  + 
		 '   </div>  '  + 
		 '  </div>  ' ; 
 
       
	
			
			 
        }
		
		return sectiondata1;
		
	
		
		
		
		
    },
    function(error) {
        parent.Xrm.Utility.alertDialog(error.message);
    }
);
	
}


*This post is locked for comments

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

    Hi,

    This is because synchronous calls are deprecated in most browsers due to potential performance overhead.

    So the workaround is to use single function where in the first web api call on success method  call second web api and inside second web api onsuccess write your actual logic instead of redirecting different function.

  • madiri Profile Picture
    242 on at

    Hi Goutam can you give me sample code  how to call two web api in one function please...

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

    Hi ,

    Try with this -

    var sectionduplicate;
    function getassementdata() {
    
        var lookupvalue1 = parent.Xrm.Page.getAttribute("aah_assessmentid");
        if (lookupvalue1 != null) {
            var lookup = lookupvalue1.getValue();
            if ((lookup != null)) {
                if (lookup[0].id != null) {
                    var lookup1 = new Array();//create a new Array
                    lookup1[0] = new Object();
                    lookup1[0].id = lookup[0].id;//retrieve the id of the record
                    lookup1[0].name = lookup[0].name;//retrieve the name of the record
                    lookup1[0].entityType = lookup[0].entityType;//retrieve the entitytype
                    //here set lookup field one value into second look up Field
                    parent.Xrm.WebApi.online.retrieveMultipleRecords("aah_aah_assessment_aah_section", "?$select=aah_assessmentid,aah_sectionid&$filter=aah_assessmentid eq" + " " + lookup[0].id).then(
                        function success(results) {
                            for (var i = 0; i < results.entities.length; i++) {
                                var aah_assessmentid = results.entities[i]["aah_assessmentid"];
                                var aah_sectionid = results.entities[i]["aah_sectionid"];
    
                                parent.Xrm.WebApi.online.retrieveMultipleRecords("aah_section", "?$select=aah_name,aah_sectionid&$filter=aah_sectionid eq" + " " + aah_sectionid).then(
                                    function success(results) {
                                        for (var i = 0; i < results.entities.length; i++) {
                                            var aah_name = results.entities[i]["aah_name"];
                                            var aah_sectionid = results.entities[i]["aah_sectionid"];
                                            sectionduplicate += '<div class="card" id="' + aah_sectionid + '">  ' +
                                                '       <div class="card-header" role="tab" id="' + aah_name + '">  ' +
                                                '         <h5 class="mb-0">  ' +
                                                '           <a data-toggle="collapse" href="#' + aah_sectionid + '" aria-expanded="true" aria-controls="' + aah_sectionid + '">  ' +
                                                aah_name +
                                                '           </a>  ' +
                                                '         </h5>  ' +
                                                '   </div>  ' +
                                                '   <div id="' + aah_sectionid + '" class="collapse show" role="tabpanel" aria-labelledby="' + aah_sectionid + '" data-parent="#accordion">  ' +
                                                '         <div class="card-body">  ' +
    
                                                '         </div>  ' +
                                                '   </div>  ' +
                                                '  </div>  ';
                                        }
    
                                    },
                                    function (error) {
                                        parent.Xrm.Utility.alertDialog(error.message);
                                    });
    
                            }
                        },
                        function (error) {
                            parent.Xrm.Utility.alertDialog(error.message);
                        }
                    );
                    // Xrm.Page.getAttribute("new_lookupfield2").setValue(lookup1);
                }
    
            }
        }
    }


  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi,

    For further read, take a look at this article-

    community.dynamics.com/.../making-xrm-webapi-synchronous-calls-in-v9

    Hope this helps.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans