Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Return value is coming as Undefined in in webapi in JS

Posted on by 20

i am trying frame this below code , when i am returing value into the 1st function i am getting process as undefined , can anyone guide me how to achive it.

dnd.Webresources.Application = {
ProcessValidation : false,
SupportedApplicationReadOnly : function(executionContext) {
var formContext = executionContext.getFormContext();
var businessunitId = formContext.getAttribute("dnd_applicationrootbusinessunit").getValue()[0].id;
businessunitId = businessunitId.substring(1, businessunitId.length - 1);
// To get child record count //
var process = dnd.Webresources.Application.Process(businessunitId);
alert(process);
},

Process: function (businessunitId) {

var query = "?$expand=dnd_businessunit_dnd_process_businessunit($select=dnd_processid)";
Xrm.WebApi.online.retrieveRecord("businessunit", businessunitId, query).then(
function success(results) {
var businessunitid = results["businessunitid"];
if (results.dnd_businessunit_dnd_process_businessunit.length > 0) {
return true;
} else {
return false;
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
}
);
}
}

regards,

vinay 

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Return value is coming as Undefined in in webapi in JS

    Hi ,

    This is due to Asynchronous call as now days most of the browser does not support (deprecated)client side Synchronous call. So try to write code in the same function instead of calling different method. And inside success method do your operation by getting the value.

    If I am not wrong seen your another post hiding ribbon button ,I have given you sample blog reference written by Andrew Butenko , which should work for you.

    https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/373883/i-need-to-hide-home-grid-button-based-on-return-values-in-javascript

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans