Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Executing custom action using javascript is failing in dynamics crm UCI page.

Posted on by 5

This question is related to Dynamics CRM 365 cloud version 9.

I created a custom action namely wfrv_GetOpportunity and I wanted to execute this custom action using java script in a ribbon button command.
I created a request variable which contains the custom action name and its metadata.
Then i used web api call to execute the custom action like following.

Xrm.WebApi.online.execute(request).then(
function (result) {
if (result.ok) {
result.json().then(function (response) {
if (response.OpportunityModel) {
opportunityModelReceived = JSON.parse(response.OpportunityModel);
}
});
}
},
function (error) {
consol.log(error.message);
}
);

Everything worked fine till i used classic CRM pages.
When i migrated to UCI CRM page, the above web api call was giving error.
When i debugged found out that web api call received a error message BAD REQUEST with error code 400. I did not modify anything in the request object.

So Web api execute method for executing custom action is working fine when i use classic crm page but not working when i use UCI crm page.

Any suggestion to solve this problem will be highly appreciated.

Thanks,
Bibhu

Categories:
  • Scosec Profile Picture
    Scosec 95 on at
    RE: Executing custom action using javascript is failing in dynamics crm UCI page.

    You could check your network inspector within your browser and find the XHR request an find any error in the response.

    Otherwise plugin logging like mentioned earlier.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Executing custom action using javascript is failing in dynamics crm UCI page.

    I don't see any issues here. I believe that you have the plugin that handles the message on the backend. Can you please provide the code of the plugin?

  • RE: Executing custom action using javascript is failing in dynamics crm UCI page.

    Hi Andrew,

    Please find screenshot of action.5305.customAction.PNG

  • RE: Executing custom action using javascript is failing in dynamics crm UCI page.

    Hi Andrew,

    Here is the code for generating the request.

    var getOpportunity = function (action, parameters) {

                   this.OpportunityId = parameters.OpportunityId;

                   this.Lob = parameters.Lob;

                   this.ShowFinalAwardedRoleSelection = parameters.ShowFinalAwardedRoleSelection;

                   this.HasCreditFlag = parameters.HasCreditFlag;

                   this.IsMnpOpp = parameters.IsMnpOpp;

                   this.ApplicationDate = parameters.ApplicationDate;

                   this.IsLoanMod = parameters.IsLoanMod;

                   this.IsLoanOrig = parameters.IsLoanOrig;

                   this.getMetadata = function () {

                       return {

                           boundParameter: null,

                           operationType: 0,

                           parameterTypes: {

                               "OpportunityId": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "Lob": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "ShowFinalAwardedRoleSelection": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "HasCreditFlag": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "IsMnpOpp": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "ApplicationDate": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "IsLoanMod": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                               "IsLoanOrig": {

                                   "typeName": "Edm.String",

                                   "structuralProperty": 1 // Primitive Type

                               },

                           },

                           operationName: action  //this is the action name that is wfrv_GetOpportunity

                       };

                   };

               };

               var request = new getOpportunity(action, parameters);

               Xrm.WebApi.online.execute(request).then(

                   function (result) {

                       if (result.ok) {

                           result.json().then(function (response) {

                               if (response.OpportunityModel) {

                                   opportunityModelReceived = JSON.parse(response.OpportunityModel);

                               }

                           });

                       }

                   },

                   function (error) {

                       consol.log(error.message);

                   }

               );

  • a33ik Profile Picture
    a33ik 84,321 Most Valuable Professional on at
    RE: Executing custom action using javascript is failing in dynamics crm UCI page.

    Hello,

    Can you please provide screenshot of your action and code that you use to generate request.

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,532 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,501 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans