Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
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

  • 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,323 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,323 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans