Announcements
Hi,
I'm trying to replace the Xrm.Page collection in a script that fires on loading cases, in order to switch to the new Unified Interface. As documentation say, I enabled the flag to pass the execution context as the first parameter, and in the function I added the executionContext in input. I still can't retrieve the value of any of the case fields, the error I receive is "getAttribute is not a function"
The function code is the follow:
function form_onload(executionContext) {
var formContext = executionContext.getFormContext();
alert(formContext.getAttribute("incidentid").getValue());
}
I tried with this way too:
executionContext.getFormContext.ui.controls.get
but it still give me an error:Cannot read property 'controls' of undefined
Can someone help me please?
Thanks
Passaia
Hi, Leah Ju solution works perfectly, thanks!
Hi Partner,
Has the problem been solved? Any updates?
Please click Yes under "Did this answer your question?" to close this thread.
Thanks.
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
Hi passaia,
You can use following code to get stage id and stage name when you move next stage every time.
And you just add the js to the form onload event.
function formonload() { Xrm.Page.data.process.addOnStageChange(getStage); // Trigger the function when move to next stage. getStage(); } function getStage() { var activeStage = Xrm.Page.data.process.getActiveStage(); var stageId = activeStage.getId(); var stagename = activeStage.getName(); alert("stageId is:" stageId , "stagename is:" stagename); }
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
Hello,
Are you talking about Active Stage Id from BPF? In this case following should work:
var formContext = executionContext.getFormContext(); var stageId = formContext.data.process.getActiveStage().getId();
You can check following articles as references:
Thanks Leah Ju, it works!
Just another question: can you tell me how I can get stageid field?
I can't find it.
Thanks
Hi passaia,
If you want to get id od the current record, you need use following code:
function getId(executionContext) { var formContext = executionContext.getFormContext(); var incident= formContext.data.entity.getId().replace('{', '').replace('}', ''); alert(incident); }
Test:
Regards,
Leah Ju
Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365 Forums.
Hi,
Can you try to replace incidentid with any other field which is available on the form like below I am getting ticket number field.
function form_onload(executionContext) {
var formContext = executionContext.getFormContext();
alert(formContext.getAttribute("ticketnumber").getValue());
}
I don't think primary field of an entity will be available on the form.
André Arnaud de Cal... 291,359 Super User 2024 Season 2
Martin Dráb 230,370 Most Valuable Professional
nmaenpaa 101,156