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

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745640545a4637663.html

相关推荐

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

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

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信