Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

how to pass variable out of Xrm.WebApi callback?

(0) ShareShare
ReportReport
Posted on by 1,016

pxLstGuid.PNG

Alert dialog comes up "undefined".  Why?

  • Manish Jain Profile Picture
    Manish Jain 50 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    This url might help if you are using response of one async call in next call based on output of first

    debajmecrm.com/.../

    Thanks

  • Manish Jain Profile Picture
    Manish Jain 50 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    This url might help if you are using response of one async call in next call based on output of first

    debajmecrm.com/.../

    Thanks

  • Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    I think what is happening is that you have two different events: the one that fills your pxtLstGuid (where there are all those async calls) and the other associated to the lookup field. So when your second event is triggered, it will probably load all javascripts again and then your context is lost, hence the variables are undefined.

    So I think you will have to get the attribute again. Or create a hidden field which you will populate on the first event, so that you can retrieve it with the formContext.getAttribute("attribute_name").getValue().

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,016 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    Thanks.  result["_defaultpricelevelid_value"] is one of the arguments to the next async.  I know the next function is receiving it and (as pretty much everything in javascript) it's a string.  Hence my question, why is the alert coming up "undefined".

  • erhan.keskin Profile Picture
    erhan.keskin 2,253 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    Hi,

    Please check if Sdk.pxLstGuid's value has a valid value. If so, convert the value to string.

    Regards,

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,016 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    My goal is to not have to find the pricelevelid a second time since I have it in hand during the onLoad.

  • Martin Donnelly Profile Picture
    Martin Donnelly 1,016 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    Sorry!  I knew that would be a question.  The series of asyncs end in adding a custom view to a lookup.  The someOther is that lookup field.  So, I am certain it is completed before I select the value (because it is coming from my custom view.)

    I even tried ExecutionContext.SharedValues and got the same result.

    thank you for looking.

  • Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: how to pass variable out of Xrm.WebApi callback?

    Hi mardukes,

    When does your function someOtherOnChangeEvent() is called? All those functions you are calling are async calls. Probably, when you are calling someOtherOnChangeEvent(), the Sdk.pxLstGuid is not filled yet, because it is being filled on an async function. That's why he is undefined.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans