Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

How to display response of custom plugin on CRM Web From?

Posted on by Microsoft Employee

I have a requirement in which on a form button named Track Shipment  click I need to call my custom plugin which is implementing  FedEx tracking web services (WSDL) 

This service takes tracking number as input & get the JSON response.

Now the issue is how can I display that JSON Response on CRM web form?

Or Is there any other why to full fill this requirement?

*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to display response of custom plugin on CRM Web From?

    I would recommend to use CRMRestBuilder to build your request.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to display response of custom plugin on CRM Web From?

    I tried what you suggested.

    Now I have registered my Plugin and created on action. Plugin is taking Action as Message.

    Now when I am trying to call my Action using javascript Its show me 404.

    POST https://wcst-test.crm.dynamics.com/api/data/v9.0/wcsti_mailitems(79C5521D-8149-E911-XXXX-XXXXXXXXX)/Microsoft.Dynamics.CRM.new_FedEXTracking  404 

    JavaScript Code 

    function CallFexExActionPlugin() {
    	var organizationUrl = Xrm.Page.context.getClientUrl();
    	var query = "wcsti_mailitems(" + Xrm.Page.data.entity.getId().replace('{', '').replace('}', '') + ")/Microsoft.Dynamics.CRM.new_FedEXTracking";
    
    	var val =
    	{
    		"TrackingNumber": Xrm.Page.getAttribute("wcsti_trackingnumber").getValue()
    
    	};
    	console.log("CallFexExActionPlugin")
    
    	var data = JSON.stringify(val);
    
    	$.ajax({
    		url: organizationUrl + "/api/data/v9.0/" + query,
    		type: 'POST',
    		contentType: "application/json; charset=utf-8",
    		async: false,
    		datatype: "json",
    		data: data,
    		beforeSend: function (XMLHttpRequest) {
    			//Specifying this header ensures that the results will be returned as JSON.
    			XMLHttpRequest.setRequestHeader("Accept", "application/json");
    		},
    		success: function (responseText) {
    			console.log(responseText)
    			alert("Action called");
    			return false;
    
    		},
    		error: function (jqXHR, exception) {
    			var msg = '';
    			if (jqXHR.status === 0) {
    				msg = 'Not connect.\n Verify Network.';
    			} else if (jqXHR.status == 404) {
    				msg = 'Requested page not found. [404]';
    			} else if (jqXHR.status == 500) {
    				msg = 'Internal Server Error [500].';
    			} else if (exception === 'parsererror') {
    				msg = 'Requested JSON parse failed.';
    			} else if (exception === 'timeout') {
    				msg = 'Time out error.';
    			} else if (exception === 'abort') {
    				msg = 'Ajax request aborted.';
    			} else {
    				msg = 'Uncaught Error.\n' + jqXHR.responseText;
    			}
    			console.log(msg);
    		}
    	});
    }



  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to display response of custom plugin on CRM Web From?

    Thanks I will try this solution.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to display response of custom plugin on CRM Web From?

    Hello,

    My recommendation is following:

    1. Create an action that has both input and output parameters.

    2. Write a plugin that will handle message of this action, get input parameters, call external endpoint, get a response and put your reply JSon to output parameter of action.

    3. Call this action using JavaScript and WebApi and use response that you got from endpoint.

    Good luck!

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans