最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Form Context in Dynamics 365 version 9 - Stack Overflow

matteradmin8PV0评论

I need to access a control of a web resource to refresh it. According to the link below we need to have the form context.

But I am unable to get the form context and couldn't find it anywhere in the documentation on how to access the execution context in the HTML web resources. I have tried registering a function on load of the form and passing execution parameter in it using form properties. Then in the function I am getting it like below with formContext variable as a global variable.

var formContext;
function getFormExecutionContext(executionContext) {
    formContext =  executionContext.getFormContext();  
    console.log("Form Context: "); 
    console.dir(formContext); 
}

However when I tried to access this formContext in other HTML web resource placed on CRM form, it says undefined. Can someone please explain how can we get the form context in HTML web resource?

I need to access a control of a web resource to refresh it. According to the link below we need to have the form context.

But I am unable to get the form context and couldn't find it anywhere in the documentation on how to access the execution context in the HTML web resources. I have tried registering a function on load of the form and passing execution parameter in it using form properties. Then in the function I am getting it like below with formContext variable as a global variable.

var formContext;
function getFormExecutionContext(executionContext) {
    formContext =  executionContext.getFormContext();  
    console.log("Form Context: "); 
    console.dir(formContext); 
}

However when I tried to access this formContext in other HTML web resource placed on CRM form, it says undefined. Can someone please explain how can we get the form context in HTML web resource?

Share Improve this question edited Jul 16, 2018 at 2:10 Arun Vinoth PrecogTechnologies 22.9k17 gold badges64 silver badges181 bronze badges asked Jan 10, 2018 at 13:46 Bilal HussainBilal Hussain 1915 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Normally we will include the below snippet in HTML webresource head section, this will present you the CRM context & controls outside CRM form.

<head>
    <title>HTML Web Resource</title>
    <script src="../ClientGlobalContext.js.aspx" type="text/javascript" ></script>
</head>

Then access the controls like following:

parent.Xrm.Page.getAttribute("my_control").getValue();

The same should work in v9 as well for backward patibility, may be not mentioned in documentation.

In case your ribbon button is on subgrid and there you need to access FormContext in version 9.0 or after, here is the detail.

In Ribbon part, pass the below parameter.

<Actions>
    <JavaScriptFunction FunctionName="subgridEvent" Library="$webresource:new_contactformload.js"> 
        <CrmParameter Value="PrimaryControl" /> 
     </JavaScriptFunction>
</Actions>

And here is the function to access the Form Context.

function ribbonHandler(e) { 
    var formContext = e.getFormContext();
    var recordId = formContext.data.entity.getId(); 
    var fieldValue = formContext.getAttribute("<field_name>").getValue(); 
}

Here is the Reference which saved my time.

Post a comment

comment list (0)

  1. No comments so far