最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论